Datatable select with multiple conditions SQL Query issue
50,878
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 & "'")
Author by
AbdulAziz
Updated on July 09, 2022Comments
-
AbdulAziz almost 2 years
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 & "'")
-
wpcoder almost 7 yearsYou can refer to this link: have more explanation: csharp-examples.net/dataview-rowfilter
-
-
vikas over 11 years@AbdulAziz did u try my logic
-
AbdulAziz over 11 yearsThis also for the single sort expression as i mention Dim results As DataRow() = table.Select("A = " + Varfoo) which is working fine. But I want for multiple sort expressions using 'AND'.
-
AbdulAziz over 11 yearsHey I got it working with your answer. Thanks a lot Man. Please see my edited question for how i solved it.