gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:44:35 25 4
gpt4 key购买 nike

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

已编辑

对于或运算

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

关于具有多个条件的数据表选择SQL查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14434867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com