如果我只添加一个查询,例如hostnameQuery
,则代码可以正常工作,因为您可以看到我尝试添加多个。
我尝试在MySqlCommand上使用+ and &
但是我收到了语法错误。
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
答案 0 :(得分:0)
尝试:
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))