I am developing a search engine within WindowsForms,
I’m using VB.Net 2010 and SQL Server 2008,
My connection is ADO.Net
I experience difficulties in concatenating strings whenever I retrieve records from the database using a textbox, combobox and a radiobutton.
I would like to retrieve record based from the values of those objects,
Dim Condition1 As String = TextBox1.Text
Dim Condition2 As String = ComboBox1.Text
Dim Condition3 As String = RadioButton.Text
When I try to concatenate, I use the operator AND..
SELECT * FROM TableName WHERE (Condition1 AND Condition2 AND Conditon3)
It gives me an error when some objects doesnt have a value.
Incorrect syntax near the word AND.
NEVER concatenate strings to make queries! use SQL Parameters! The query you posted is prone to SQL Injection.
Apart from the above, the conditions you are trying to concatenate are not valid. Anything that comes after the
WHEREclause should specify the column name and the value like what I did above. So condition1 should be for example :