我一直在尝试获取我在数据库中的记录,但它还没有正常工作。试图搜索一些代码。它对他们有用,但对我不起作用。
Try
Dim cn As New MySqlConnection(ConnectionString)
Dim cmd As New MySqlCommand("SELECT CONCAT(Surname, ', ', FirstName) as 'Name' FROM tbl_ClassList", cn)
Dim reader As MySqlDataReader = cmd.ExecuteReader
Do While reader.Read
Console.WriteLine(reader.Item("Name").ToString())
Loop
reader.Close()
cmd.Dispose()
cn.Close()
Catch ex As Exception
MsgBox("Wrong")
End Try
答案 0 :(得分:1)
您忘了打开连接:
Dim cn As New MySqlConnection(ConnectionString)
cn.Open()