Datatable select with multiple conditions SQL Query issue

AbdulAziz picture AbdulAziz · Jan 21, 2013 · Viewed 44.2k times · Source

From This question, its answer is almost my answer. But I am facing some sql query issue, I have the following statement in VB

Dim results As DataRow() = table.Select("A = 'foo' AND B = 'bar' AND C = 'baz'")

I want to place foo, bar and baz in variables and use that variables in above statements.

Dim Varfoo As String = "foo"
Dim Varbar As String = "bar"
Dim Varbaz As String = "baz"

I managed to get one variable in statement as

 Dim results As DataRow() = table.Select("A = " + Varfoo)

But how to insert multiple sort expressions with variables?

Edit: I got it solved with the answer of vikas as following;

Dim results As DataRow() = table.Select("A = '" & Varfoo & "' And B = '" & Varbar & "' And C = '" & Varbaz & "'")

Answer

vikas picture vikas · Jan 21, 2013

Have you tried

Dim results As DataRow() = table.Select("A = '" & Varfoo & "'")

Edited

For OR operation

Dim results As DataRow() = table.Select("A = '" & Varfoo & "' OR B = '" & Varbar & "' OR C = '" & Varbaz & "'")

For AND operation

Dim results As DataRow() = table.Select("A = '" & Varfoo & "' AND B = '" & Varbar & "' AND C = '" & Varbaz & "'")