Last post Mar 15, 2011 12:20 PM by AlexLaV
Mar 15, 2011 11:23 AM|AlexLaV|LINK
I'd like to find the value of Field1 in my database table "TableA" where VariableA=1 and VariableB=2.
This is the code I have:
FROM TableA WHERE VariableA=1,VariableB=2";
However I get error:
Details: System.Data.SqlClient.SqlException: Incorrect syntax near ','.
presumably it doesn't like having two things in the WHERE part. Is it impossible to have two variables in this section?
Mar 15, 2011 11:31 AM|limno|LINK
dataX.CommandText = "Select Field1 FROM TableA
WHERE someCol1=@var1 AND someCol2=@var2"
Assign your variable values through paramters:
Mar 15, 2011 11:35 AM|GauravSingla|LINK
Replace comma in your commandtext with and operator.
dataX.CommandText = "Select Field1 FROM TableA WHERE VariableA=1 and VariableB=2";
Mar 15, 2011 11:36 AM|asheejtk|LINK
If you have multiple condition in where clause then you have to use "and"
Check below query,
"Select Field1 FROM TableA WHERE VariableA=1 AND VariableB=2";
Mar 15, 2011 12:20 PM|AlexLaV|LINK
I can't believe that was the problem, I was sure I'd tried that. I've been struggling to get to the bottom of this for hours, so simple!
Maybe I only tried using the + symbol instead of AND. I must have seen that used in an example somewhere online.