gpt4 book ai didi

mysql - 你调用的对象是空的

转载 作者:行者123 更新时间:2023-11-29 21:51:53 24 4
gpt4 key购买 nike

 Private Sub btnSelectAsset_Click(sender As Object, e As EventArgs) Handles btnSelectAsset.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password= ;database=myma"
Dim SDA As MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource

Try
MySqlConn.Open()
COMMAND.Connection = MySqlConn
SDA = New MySqlDataAdapter("select * from myma.user", MySqlConn)
dbDataSet = New DataTable
SDA.Fill(dbDataSet)
DataGridView1.DataSource = dbDataSet
MySqlConn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub

object reference not set to an instance of an object.

调试时出现上述错误。您能帮我纠正这个问题吗?

最佳答案

尝试这个工作示例:

Private Sub btnSelectAsset_Click(sender As Object, e As EventArgs) Handles btnSelectAsset.Click
Dim dbConn = New MySqlConnection
Dim dbDataTable = New DataTable

dbConn.ConnectionString = "server=localhost;userid=root;password= ;database=myma"

Try
dbConn.Open()
If (dbConn.State = ConnectionState.Open) Then
Dim dbAdapter = New MySqlDataAdapter("select * from myma.user", dbConn)
dbAdapter.Fill(dbDataTable)
DataGridView1.DataSource = dbDataTable
dbConn.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
dbConn.Dispose()
End Try
End Sub

VB2010Ex 和 .NET 4 客户端配置文件。

关于mysql - 你调用的对象是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33560099/

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