Private Sub View_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''Search All data
Dim Reader As MySqlDataReader
Dim Query As String
Try
myConn.Open()
Query = "SELECT*FROM datainfo"
myComman = New MySqlCommand(Query, myConn)
Reader = myComman.ExecuteReader
While Reader.Read
Dim sName = Reader.GetString("StudentName")
ComboBox1.Items.Add(sName)
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
myConn.Dispose()
End Try
答案 0 :(得分:0)
声明数据连接myConn的方式不完整。 有很多关于如何通过快速谷歌搜索来做到这一点的例子。 如果您在配置文件中定义了连接,那么它将是:
Dim myConn as New SqlConnection(configurationManager.ConnectionStrings("MyConn").ConnectionString)
在不相关的说明中,您将要关闭数据库连接并处理该命令。所以
Finally
myConn.close()
myComman.dispose()
垃圾收集器会自动为您处理该命令,但不会自行处理任何事情。