数据表选择具有多个条件的SQL Query问题

前端之家收集整理的这篇文章主要介绍了数据表选择具有多个条件的SQL Query问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
This question开始,它的答案几乎就是我的答案.但我面临一些SQL查询问题,我在VB中有以下语句
Dim results As DataRow() = table.Select("A = 'foo' AND B = 'bar' AND C = 'baz'")

我想将foo,bar和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 & "'")

解决方法

你有没有尝试过
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 & "'")

猜你在找的MsSQL相关文章