PC Review


Reply
Thread Tools Rate Thread

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

 
 
Jeff Thur
Guest
Posts: n/a
 
      9th Mar 2005
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

 
Reply With Quote
 
 
 
 
Bernie Yaeger
Guest
Posts: n/a
 
      9th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:4d8101c524de$aa4a68b0$(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      9th Mar 2005

>-----Original Message-----
>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
>

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" <(E-Mail Removed)> wrote in message
>news:4d8101c524de$aa4a68b0$(E-Mail Removed)...
>>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
>>

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Pass Parameter to stored procedure in pass thru query SAC Microsoft Access Queries 7 11th Jul 2007 12:49 PM
Pass-through to stored procedure Hoardling via AccessMonster.com Microsoft Access ADP SQL Server 1 10th May 2007 05:09 PM
How to pass a null value for a stored procedure? =?Utf-8?B?QW5kcmV3?= Microsoft ADO .NET 3 19th Nov 2004 08:24 PM
Pass Through to Stored Procedure Brian Microsoft Access Queries 3 19th Apr 2004 08:32 PM
Error: Executing Stored Procedures-- Cannot Pass TimeStamp Values From sqlCommand Object Parameter to A SQL Stored Procedure =?Utf-8?B?VGVjaE1E?= Microsoft ADO .NET 3 17th Mar 2004 04:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 PM.