8

这个问题,它的答案几乎就是我的答案。但我面临一些 sql 查询问题,我在 VB 中有以下语句

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)

但是如何使用变量插入多个排序表达式?

编辑:我用vikas的回答解决了它,如下所示;

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

1 回答 1

13

你有没有尝试过

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

已编辑

用于 OR 操作

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

对于 AND 运算

Dim results As DataRow() = table.Select("A = '" & Varfoo & "' AND B = '" & Varbar & "' AND C = '" & Varbaz & "'")
于 2013-01-21T08:38:15.673 回答