Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to select a text from an combo box and give that as a parameter to an sql query

i have written the query as below:

VB
Dim strSelect As String = "SELECT * FROM Table1 WHERE city='ComboBox1.SelectedItem()'"
Dim da As New OleDbDataAdapter(strSelect, con)
Dim ds As New DataSet
da.Fill(ds, "city")




but i am getting error ,can u please tell me how to write query to accept input from combobox

thanks
Posted
Updated 23-Aug-11 8:48am
v2

Try this:

VB
Dim strSelect As String = string.Format("SELECT * FROM table1 WHERE city='{0}'", ComboBox1.SelectedItem)
 
Share this answer
 
Comments
l_d 23-Aug-11 15:22pm    
thank you
walterhevedeich 23-Aug-11 22:05pm    
+5
I think select string should be something like this -
VB
Dim strSelect As String = "SELECT * FROM Table1 WHERE city='" & ComboBox1.SelectedItem() & "'"
 
Share this answer
 
Comments
l_d 23-Aug-11 15:21pm    
thank you
walterhevedeich 23-Aug-11 22:05pm    
+5
SQL
Dim strSelect As String = "SELECT * FROM Table1 WHERE city='" & ComboBox1.SelectedItem& "'"
 
Share this answer
 
v2
Comments
l_d 23-Aug-11 15:20pm    
thank you
walterhevedeich 23-Aug-11 22:05pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900