Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatable select with multiple conditions SQL Query issue

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 & "'")
like image 384
AbdulAziz Avatar asked Jan 21 '13 08:01

AbdulAziz


1 Answers

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 & "'")
like image 85
vikas Avatar answered Oct 01 '22 18:10

vikas