Datatable Select with Multiple Conditions Sql Query Issue

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 & "'")
1

1 Answer

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 & "'")
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.