J
Jeff Thur
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
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