我正在研究这个项目,我想在VB.NET的datagridview中显示MySQL表的内容。
检索表的查询工作正常,但是当我运行程序时,它不会在显示的表中显示任何数据。
我正在使用的代码:
Private Sub Products_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SearchTextBox.Enabled = False
Label1.Enabled = False
SqlConn = New MySqlConnection
SqlConn.ConnectionString = "Server=localhost;userid=root;password=;database=osap"
Dim data As MySqlDataAdapter
Try
SqlConn.Open()
data = New MySqlDataAdapter("SELECT products.id, inventory, description, products.name, categories.name as category, price FROM products INNER JOIN branches ON products.branch_id = branches.id INNER JOIN categories ON products.category_id = categories.id WHERE branch_id ='" & LoginForm.BranchIDTextBox.Text & "' ", SqlConn)
productstable = New DataTable
data.Fill(productstable)
ProductsDataGridView.DataSource = productstable
ProductsDataGridView.ReadOnly = True
SqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
SqlConn.Dispose()
End Try
End Sub
为什么我在DataGridView中没有得到任何结果?
答案 0 :(得分:0)
不确定我是怎么看不到的 - 你没有绑定你的数据:
ProductsDataGridView.DataSource = productstable
ProductsDataGridView.DataBind()