我尝试使用DataGridView
DataTable
这是执行查询的方法(此方法在其他类中称为MySQL
)
Public Function WykonajZapytanie(sql As String) As DataTable
Dim dt As DataTable
Try
Connect()
Dim da As New MySqlDataAdapter(sql, connection)
dt = New DataTable()
da.Fill(dt)
Catch ex As MySqlException
...
Catch ex As Exception
...
Finally
Disconnect()
End Try
Return dt
End Function
这是一个应该从DataTable填充datagridview的方法:
Public Sub WyswietlNoweZamowienia()
Dim mySql As New MySQL
Dim dt As New DataTable
Dim sql As String = "SELECT * FROM KLIENCI"
dt = mySql.WykonajZapytanie(sql)
Try
DataGridView1.DataSource = dt 'Here it doesn't populate dgv
Catch ex As Exception
...
End Try
End Sub
我没有任何错误或其他什么。代码只是没有填充DataGridView。我做错了什么?
PS。与数据库的连接工作正常。