tags:

views:

14

answers:

3

Hello,

I just want to display data in a DataGridView (from SQL - already made the connection) based on what is selected in a ComboBox (data that is also coming from SQL). The 2 are separete on the form. I am using VB 2010.

This doesn't work for me: objCommand2.CommandText = "SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product WHERE ProductCategoryID = " & cbCategory.SelectedValue

It gives me an error "invalid syntax around '=' "

Thank you!!! Catalin

A: 

Try this

cbCategory.SelectedText

and look into passing command parameters to a stored procedure in the future.

Saif Khan
Catalin
A: 

Have you tried to assign the long string to a variable first to see if it really looks like a SQL statement. As Saif suggested, it may be something related to the value of the combobox. What I usually do is hardcode a SQL statement in a string to make the function work and then replace it with the dynamic string.

Dim s As String = "SELECT ProductID FROM SalesLT.Product WHERE ProductCategoryID=1"

One simple step at a time

Miroslav Jeliaskoff
A: 

Check that cbCategory.SelectedValue is indeed a numeric value. If it is, say "XXY", then you would need to code

WHERE ProductCategoryID = '" & cbCategory.SelectedValue & "'"

(watch out for the difference between ' and " !

smirkingman