By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,584 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,584 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
-----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 discussion thread is closed

Replies have been disabled for this discussion.