Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 query data base with list box value

Author  Topic 

alxtech
Yak Posting Veteran

66 Posts

Posted - 2006-02-01 : 12:25:49
hello forum,

I need to grab a string value from a list box in from a web form,
and pass it to a sql select command statement where that value is equal to
all values in a database table(sql 2000).

example

zip code list box
33154
33254
84578
85475
35454

selected value is 85475

I am putting that value in a string like this:

dim string_zip as string
string_zip = zip_ListBox.text

Question, how do i pass that value to sql stament, i am using this but does not work.

SqlCommand1 = New SqlCommand("SELECT zip FROM table WHERE zip = string_zip", SqlConnection1)

jhermiz

3564 Posts

Posted - 2006-02-02 : 14:38:56
quote:
Originally posted by alxtech

hello forum,

I need to grab a string value from a list box in from a web form,
and pass it to a sql select command statement where that value is equal to
all values in a database table(sql 2000).

example

zip code list box
33154
33254
84578
85475
35454

selected value is 85475

I am putting that value in a string like this:

dim string_zip as string
string_zip = zip_ListBox.text

Question, how do i pass that value to sql stament, i am using this but does not work.

SqlCommand1 = New SqlCommand("SELECT zip FROM table WHERE zip = string_zip", SqlConnection1)




You should be using stored procedures, dynamic sql is a no no.

Anyhow:

strSQL = "SELECT zip FROM myTable WHERE zip= '" & MyTextbox.Text & "'"
SQLCommand1= New SQLCommand(strSQL, SQLConnection1)



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page
   

- Advertisement -