473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Command Type = CommandType.Sto redProcedure

Dim Last As SqlParameter = testCMD.Paramet ers.Add
("@Last", SqlDbType.VarCh ar, 6)
Last.Value = TxtLast.Text

Dim First As SqlParameter = testCMD.Paramet ers.Add
("@First", SqlDbType.VarCh ar, 1)
First.Value = TxtFirst.Text

Dim Subscr As SqlParameter = testCMD.Paramet ers.Add
("@Subscr", SqlDbType.VarCh ar, 10)
Subscr.Value = TxtSubscr.Text

Dim State As SqlParameter = testCMD.Paramet ers.Add
("@State", SqlDbType.VarCh ar, 2)
State.Value = State.SelectedV alue
MyConnection.Op en()

TxtCount.Text = testcmd.Execute Scalar()
MyConnection.Cl ose()
End Sub

Jul 21 '05 #1
2 4592
Hi Jeff,

Use cbname.selected item. But you have .state.selected value - 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.c om> 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.Command Type = CommandType.Sto redProcedure

Dim Last As SqlParameter = testCMD.Paramet ers.Add
("@Last", SqlDbType.VarCh ar, 6)
Last.Value = TxtLast.Text

Dim First As SqlParameter = testCMD.Paramet ers.Add
("@First", SqlDbType.VarCh ar, 1)
First.Value = TxtFirst.Text

Dim Subscr As SqlParameter = testCMD.Paramet ers.Add
("@Subscr", SqlDbType.VarCh ar, 10)
Subscr.Value = TxtSubscr.Text

Dim State As SqlParameter = testCMD.Paramet ers.Add
("@State", SqlDbType.VarCh ar, 2)
State.Value = State.SelectedV alue
MyConnection.Op en()

TxtCount.Text = testcmd.Execute Scalar()
MyConnection.Cl ose()
End Sub

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

Use cbname.selected item. But you have .state.selected value - 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.c om> 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.Command Type = CommandType.Sto redProcedure

Dim Last As SqlParameter = testCMD.Paramet ers.Add
("@Last", SqlDbType.VarCh ar, 6)
Last.Value = TxtLast.Text

Dim First As SqlParameter = testCMD.Paramet ers.Add
("@First", SqlDbType.VarCh ar, 1)
First.Value = TxtFirst.Text

Dim Subscr As SqlParameter = testCMD.Paramet ers.Add
("@Subscr", SqlDbType.VarCh ar, 10)
Subscr.Value = TxtSubscr.Text

Dim State As SqlParameter = testCMD.Paramet ers.Add
("@State", SqlDbType.VarCh ar, 2)
State.Value = State.SelectedV alue
MyConnection.Op en()

TxtCount.Text = testcmd.Execute Scalar()
MyConnection.Cl ose()
End Sub

.

Jul 21 '05 #3

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

Similar topics

2
12353
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 users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations. I am trying to pass values with the help of session variables. But I have multiple if else...
2
1098
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 Select Statement and it fills the ddl. Is there any way of using a stored procedure instead of just a Select? --
2
380
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 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...
1
1522
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, which works well. However this time i need to combine a set of results from two databases into a single data source so i need to use ADO to do it. The problem i come up against is that until the value in the drop ,down box is changed, the...
1
5397
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> <asp:TableCell CssClass="asp-table-header">Select Route<asp:Label ID="lblTest" runat="server"></asp:Label> </asp:TableCell>
4
8097
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 they al refer to this error when accessing data in the list box.
12
4626
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) my problem is: i have to access a temporary table created in an SP in a function
18
5423
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
10
1536
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 execute the insert. The error is "name dd is not declared" (in line: selvalue = selvalue & Session("dd" & dd.id) & ":" Any idea how to solve this?
0
8448
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7387
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.