Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Send Parameters to Stored Procedure

Reply
Thread Tools

Send Parameters to Stored Procedure

 
 
Chris
Guest
Posts: n/a
 
      03-22-2006
Hi,

How can I send the parameter value for a stored procedure in ASP.NET
2.0 ?

Dim sds_reader As New SqlDataSource

sds_reader.SelectCommand = "STP_select_by_Type"

the line below produces an error:

sds_reader.SelectParameters.Item(@Period_Type_no). DefaultValue =
1

Thanks a lot.

 
Reply With Quote
 
 
 
 
q
Guest
Posts: n/a
 
      03-22-2006
You'll have to convert it to VB... but here it is.

string connectionString =
System.Configuration.ConfigurationManager.Connecti onStrings["MyDatabase"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("DeleteOrderLine",
connection)) {
connection.Open( );
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@LineNumber", lineNumber);
command.ExecuteNonQuery( );
}
}



David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-22-2006
Try sds_reader.SelectParameters.Add(parameter_name, parameter_value)

Eliyahu

"Chris" <> wrote in message
news: oups.com...
> Hi,
>
> How can I send the parameter value for a stored procedure in ASP.NET
> 2.0 ?
>
> Dim sds_reader As New SqlDataSource
>
> sds_reader.SelectCommand = "STP_select_by_Type"
>
> the line below produces an error:
>
> sds_reader.SelectParameters.Item(@Period_Type_no). DefaultValue =
> 1
>
> Thanks a lot.
>



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      03-23-2006
I tried:

sds_reader.SelectCommand = "STP_select_by_Type"
sds_reader.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure

sds_reader.SelectParameters.Add("@Period_Type_no", 1)

and gives me an error on DATABIND saying:

Procedure or Function 'STP_select_by_Type' expects parameter
'@Period_Type_no', which was not supplied.

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      03-23-2006
Thanks a lot.

I tried the following"

Dim sds_reader1 As New SqlDataSource

sds_reader1.DataSourceMode = SqlDataSourceMode.DataReader
sds_reader1.ConnectionString =
ConfigurationManager.ConnectionStrings("SubDispCon nectionString1").ConnectionString

sds_reader1.SelectCommand = "STP_select_by_Type"
sds_reader1.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure

sds_reader1.SelectParameters.Add("@Period_Type_no" , 1)

dropdownlist.DataSource = sds_reader1
dropdownlist.DataBind()

on DATABIND I get the error :

Procedure or Function 'STP_select_by_Type' expects parameter
'@Period_Type_no', which was not supplied.

I changed it to the following, but error is still the same:

Dim a As New Parameter

a.Name = "@Period_Type_no"
a.DefaultValue = 1
sds_reader1.SelectParameters.Add(a)

 
Reply With Quote
 
q
Guest
Posts: n/a
 
      03-23-2006
You may actually want to use the method I posted (using a
SqlDataAdapter of course)... the SqlDataSource is more for declarative
databinding in the ASP.NET declarative page.

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      03-24-2006
I was able to use the code you posted after using imports
system.data.sqlclient.

Why in 2005 the SQLCOMMAND, SQLDATAADAPTER etc are not included in
toolbox as in 2003. Only SQLDATA SOURCE exists in toolbox (that's why I
was trying with that one).

Does it mean that these objects should not be used ? Sorry for my
questions, I just started using .NET and I got confused.

 
Reply With Quote
 
q
Guest
Posts: n/a
 
      03-24-2006
The controls are just there for beginners who don't really know what's
available. When you get into the CODE, you use the code. You
shouldn't really have to mix the designer with code. After a while,
the designer will be a hinderance to your productivity as SqlCommand
and SqlDataAdapter will flow from your fingers like writing an e-mail.

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      03-27-2006
Thanks a lot.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters to stored procedure from crystal reports kavitha N via .NET 247 ASP .Net 1 02-15-2011 08:20 AM
'Procedure or function <stored procedure name> has too many arguments specified',,,ARGH! Mike P ASP .Net 0 06-19-2006 01:19 PM
Error while passing input parameters to stored procedure using DAA =?Utf-8?B?TWlrZQ==?= ASP .Net 0 06-22-2005 07:44 PM
Q: number of parameters in stored procedure =?Utf-8?B?SklNLkgu?= ASP .Net 2 01-12-2005 06:42 AM
How to use parameters(record selection) and stored procedure in CR.NET web-based application? TaeHo Yoo ASP .Net 0 08-13-2003 11:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57