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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 grab value .asp form, query database

Author  Topic 

alxtech
Yak Posting Veteran

66 Posts

Posted - 2006-02-01 : 12:40:15
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)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-01 : 12:42:26
SqlCommand1 = New SqlCommand("SELECT zip FROM table WHERE zip = " & string_zip, SqlConnection1)

Tara Kizer
aka tduggan
Go to Top of Page

alxtech
Yak Posting Veteran

66 Posts

Posted - 2006-02-01 : 12:55:45
Thanks Brother,
another question,
what if multiple values are selected in form, and then pass to query.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-01 : 13:02:07
It would be sister.

You would need to use zip IN (Value1, Value2, ...)

Tara Kizer
aka tduggan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-02 : 09:07:32
Something like

string_zip=""
for i=1 to zip_ListBox.count
if zip_ListBox.selected=true then string_zip=string_zip & "," & zip_ListBox.Text
next i
string_zip=mid(string_zip,2,len(string_zip)
SqlCommand1 = New SqlCommand("SELECT zip FROM table WHERE zip in (" & string_zip & ")", SqlConnection1)



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -