2013-01-21 62 views
5

This question,其答案几乎是我的答案。但我面臨着一些SQL查詢的問題,我有以下的語句在VBDatatable選擇多個條件SQL查詢問題

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

我要放置在變量foo, bar and baz和使用,在上述聲明的變量。

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

我設法在聲明一個變量

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

但如何與變量插入多個排序表達式?

編輯:我得到了它的維卡斯如下答覆解決;

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

你可以參考這個鏈接:有更多的解釋:http://www.csharp-examples.net/dataview-rowfilter/ – wpcoder

回答

9

你試過

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

編輯

對於OR操作

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

並操作

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

@AbdulAziz你試過我的邏輯 – vikas

+0

這也適用於單排序表達式,因爲我提到Dim結果由於DataRow()= table.Select(「A =」+ Varfoo)它工作正常。但我想用多個排序表達式使用'AND'。 – AbdulAziz

+0

嘿,我得到它與您的答案一起工作。非常感謝Man。請看我編輯的問題,我是如何解決它的。 – AbdulAziz