我想在VB应用程序中显示有权访问表(MySQL)的用户列表。我想在列表框中显示它。
MysqlConn = New MySqlConnection()
MysqlConn.ConnectionString = "server=" & serverTB.Text & ";" & "user id=" & userTB.Text & ";" & _
"password=" & pwdTB.Text & ";" & "database=" & databaseTB.Text
MysqlConn.Open()
Dim cmd As New MySqlCommand()
Dim conn As New MySqlConnection(MysqlConn.ConnectionString)
conn.Open()
cmd.Connection = conn
cmd.CommandText = "SELECT USER FROM users"
Dim list = cmd.ExecuteReader()
For Each user In list
userListCBX.Items.Add(user)
Next
我在“字段列表”中未知列“USER”。我希望用户来自数据库测试,表用户。
答案 0 :(得分:1)
您需要在从当前记录中获取信息后调用Read()
将读者移至下一条记录:
Dim reader = cmd.ExecuteReader()
While reader.Read()
serListCBX.Items.Add(reader(0))
End While
请参阅MSDN中SqlCommand.ExecuteReader
的示例用法。