473,387 Members | 1,535 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,387 software developers and data experts.

How can I pass a SelectedValue from a Drop Down List to a Stored Procedure

I am running a SQL Stored Procedure that will give the
user a count of how many records are in the database as
per certain criteria.
I'm using the Execute Scalar Method.
I have no problem passing values that the user inputs
into Text boxes to my Stored Procedure. However I have a
drop down list with a listing of the individual States,
which the user selects. I am trying to use the
SelectedValue of the drop down list but I am getting a
message that SelectedValue is not a member of the
parameter collection. Would anybody know how to pass that
parameter to the Stored procedure. Below is a piece of
the program to look at. Thanks for any help that can be
provided.
Sub GetCount

Dim MyConnection As SqlConnection
MyConnection = New SqlConnection("server='(local)'; user
id='sa'; password='fritz'; database='Cutis'")
Dim testCMD As SqlCommand = New SqlCommand ("EMSCOUNTER",
MyConnection)
testCMD.CommandType = CommandType.StoredProcedure

Dim Last As SqlParameter = testCMD.Parameters.Add
("@Last", SqlDbType.VarChar, 6)
Last.Value = TxtLast.Text

Dim First As SqlParameter = testCMD.Parameters.Add
("@First", SqlDbType.VarChar, 1)
First.Value = TxtFirst.Text

Dim Subscr As SqlParameter = testCMD.Parameters.Add
("@Subscr", SqlDbType.VarChar, 10)
Subscr.Value = TxtSubscr.Text

Dim State As SqlParameter = testCMD.Parameters.Add
("@State", SqlDbType.VarChar, 2)
State.Value = State.SelectedValue
MyConnection.Open()

TxtCount.Text = testcmd.ExecuteScalar()
MyConnection.Close()
End Sub

Jul 21 '05 #1
2 4560
Hi Jeff,

Use cbname.selecteditem. But you have .state.selectedvalue - is 'state' the
name of your combobox? If it is, change it, because it's conficting with
the name of the parameter.

HTH,

Bernie Yaeger
"Jeff Thur" <je**@emscirc.com> wrote in message
news:4d****************************@phx.gbl...
I am running a SQL Stored Procedure that will give the
user a count of how many records are in the database as
per certain criteria.
I'm using the Execute Scalar Method.
I have no problem passing values that the user inputs
into Text boxes to my Stored Procedure. However I have a
drop down list with a listing of the individual States,
which the user selects. I am trying to use the
SelectedValue of the drop down list but I am getting a
message that SelectedValue is not a member of the
parameter collection. Would anybody know how to pass that
parameter to the Stored procedure. Below is a piece of
the program to look at. Thanks for any help that can be
provided.
Sub GetCount

Dim MyConnection As SqlConnection
MyConnection = New SqlConnection("server='(local)'; user
id='sa'; password='fritz'; database='Cutis'")
Dim testCMD As SqlCommand = New SqlCommand ("EMSCOUNTER",
MyConnection)
testCMD.CommandType = CommandType.StoredProcedure

Dim Last As SqlParameter = testCMD.Parameters.Add
("@Last", SqlDbType.VarChar, 6)
Last.Value = TxtLast.Text

Dim First As SqlParameter = testCMD.Parameters.Add
("@First", SqlDbType.VarChar, 1)
First.Value = TxtFirst.Text

Dim Subscr As SqlParameter = testCMD.Parameters.Add
("@Subscr", SqlDbType.VarChar, 10)
Subscr.Value = TxtSubscr.Text

Dim State As SqlParameter = testCMD.Parameters.Add
("@State", SqlDbType.VarChar, 2)
State.Value = State.SelectedValue
MyConnection.Open()

TxtCount.Text = testcmd.ExecuteScalar()
MyConnection.Close()
End Sub

Jul 21 '05 #2
-----Original Message-----
Hi Jeff,

Use cbname.selecteditem. But you have .state.selectedvalue - is 'state' thename of your combobox? If it is, change it, because it's conficting withthe name of the parameter.

HTH,

Bernie Yaeger
Hi Bernie,
Thats it. Also Would you know
How can I select multiple States from the drop down box
and pass them on to my SQL Query.

Thank You VERY MUCH.

Jeff...........
"Jeff Thur" <je**@emscirc.com> wrote in message
news:4d****************************@phx.gbl...
I am running a SQL Stored Procedure that will give the
user a count of how many records are in the database as
per certain criteria.
I'm using the Execute Scalar Method.
I have no problem passing values that the user inputs
into Text boxes to my Stored Procedure. However I have a drop down list with a listing of the individual States,
which the user selects. I am trying to use the
SelectedValue of the drop down list but I am getting a
message that SelectedValue is not a member of the
parameter collection. Would anybody know how to pass that parameter to the Stored procedure. Below is a piece of
the program to look at. Thanks for any help that can be
provided.
Sub GetCount

Dim MyConnection As SqlConnection
MyConnection = New SqlConnection("server='(local)'; user id='sa'; password='fritz'; database='Cutis'")
Dim testCMD As SqlCommand = New SqlCommand ("EMSCOUNTER", MyConnection)
testCMD.CommandType = CommandType.StoredProcedure

Dim Last As SqlParameter = testCMD.Parameters.Add
("@Last", SqlDbType.VarChar, 6)
Last.Value = TxtLast.Text

Dim First As SqlParameter = testCMD.Parameters.Add
("@First", SqlDbType.VarChar, 1)
First.Value = TxtFirst.Text

Dim Subscr As SqlParameter = testCMD.Parameters.Add
("@Subscr", SqlDbType.VarChar, 10)
Subscr.Value = TxtSubscr.Text

Dim State As SqlParameter = testCMD.Parameters.Add
("@State", SqlDbType.VarChar, 2)
State.Value = State.SelectedValue
MyConnection.Open()

TxtCount.Text = testcmd.ExecuteScalar()
MyConnection.Close()
End Sub

.

Jul 21 '05 #3

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

Similar topics

2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
2
by: Sandy | last post by:
Hello - How do I get a drop down list to drop down instead of up? Is there any way to make the text centered in the list? Also, I now have a drop down list that was created using a Sql...
2
by: Jeff Thur | last post by:
I am running a SQL Stored Procedure that will give the user a count of how many records are in the database as per certain criteria. I'm using the Execute Scalar Method. I have no problem passing...
1
by: clickon | last post by:
I want to use the selected value of a drop down list to filter a data source. When i have done this before i have used a DataSourceControl and i have just made the drop down a control parameter,...
1
by: clickon | last post by:
Forget about the controlParameter for the moment, for testing purposes i have created the following Markup: <asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table"> <asp:TableRow>...
4
by: Dooman | last post by:
Hello, I am getting this error when binding a drop down list box to a dataset: The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive I have looked at other posts and...
12
by: ArunDhaJ | last post by:
Hi Friends, Is it possible to pass a table as a parameter to a funtion. whos function declaration would look some thing like this.... ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT) ...
18
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
10
by: Dan | last post by:
Hi, I create 5 dropdownlist in code-behind. I want to insert their selectedvalues in a table by making a string separated with ":" I can get their selecedvalues but i'm stuck when i want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.