gpt4 book ai didi

mysql - 多个 MySQL 查询

转载 作者:行者123 更新时间:2023-11-30 00:18:43 26 4
gpt4 key购买 nike

如果我只添加一个查询,例如 hostnameQuery,则代码可以正常工作,正如您所看到的,我尝试添加多个查询。

我尝试在 MySqlCommand 上使用 + 和 &,但返回了语法错误。

Dim hostnameQuery As String = "SELECT `HOSTNAME` FROM `m1` WHERE 1"
Dim osQuery As String = "SELECT `OS` FROM `m1` WHERE 1"
Dim SQLConnection As New MySqlConnection(My.Settings.connStr)
Dim cmd As New MySqlCommand(hostnameQuery & osQuery, SQLConnection)

Try
SQLConnection.Open()
cmd.ExecuteNonQuery()
Dim reader As MySqlDataReader
reader = cmd.ExecuteReader
While reader.Read
main.Label64.Text = (reader.GetString(0))
main.Label65.Text = (reader.GetString(0))
End While
Catch ex As Exception
MsgBox(ex.Message.ToString)
Finally
SQLConnection.Close()

End Try

最佳答案

尝试:

Dim hostnameQuery As String = "SELECT `HOSTNAME` FROM `m1` WHERE 1 UNION ALL (SELECT `OS` FROM `m1` WHERE 1)";

或者你为什么不呢(因为你查询了 1 个表):

 Dim hostnameQuery As String = "SELECT `HOSTNAME`,`OS`  FROM `m1` WHERE 1 ";

.....

While reader.Read
main.Label64.Text = (reader.GetString(0))
main.Label65.Text = (reader.GetString(1))

关于mysql - 多个 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23427707/

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