473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Send Parameters to Stored Procedure

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.

Mar 22 '06 #1
8 5208
q
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/

Mar 22 '06 #2
Try sds_reader.SelectParameters.Add(parameter_name, parameter_value)

Eliyahu

"Chris" <CL*****@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr 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.

Mar 22 '06 #3
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.

Mar 23 '06 #4
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)

Mar 23 '06 #5
q
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.

Mar 23 '06 #6
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.

Mar 24 '06 #7
q
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.

Mar 24 '06 #8
Thanks a lot.

Mar 27 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ivan divandelen | last post by:
Hi, How can i pass a parameter SQL stored Procedure from ASP pages
0
by: Aaron | last post by:
The following code works fine when previewing a Crystal report using ASP, EXCEPT when it gets to a report using a SubReport and its associated parameters. The whole report just comes up blank with...
1
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml...
8
by: Mark Flippin | last post by:
This is for a reporting problem using: Access 2000 SQL Server 2000 Both at SP3 I've a stored procedure in SQL Server 2000 which builds a result set from a disparate set of tables, utilizing...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
2
by: Steven K | last post by:
Hello, I am trying to learn how to use Code Behind. Essentially, the example of Block 1 and Block 2 are the same. The difference is that in Block 1 I explicitly set the parameter value to...
10
by: Adis | last post by:
Asp.Net Visual Studio 2003 SQL Server. Hi, Obtaining Data Based Upon Multiple Selections From a ListBox... I have database in Sqlserver and ListBox (Multiple Selection Mode) in my Visual...
11
by: Leon | last post by:
I have six textbox controls on my webform that allows the user to enter any numbers from 1 to 25 in any order. However, I would like to sort those numbers from least to greatest before sending them...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
0
by: pisgasys | last post by:
Hi, I need to send xml file as a parameter to SQL stored procedure from Access VBA form.. I wrote code that handle sending parameters from a textbox input.. but if I need to send xml file, what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.