我是编程新手,我正在研究一个基本的VB.NET应用程序,允许用户从MySQL中选择,插入,更新和删除各种数据表。vb.net mysql combobox show tables
我遇到的麻烦是,我需要用一个特定数据库中的所有表名填充组合框,以便用户可以选择使用哪个数据库表。我认为我的代码可以工作,但是当我运行该应用时,我得到的所有内容都是空白的组合框。
有人能告诉我我的代码有什么问题吗?
非常感谢!
代码:
Private Sub TableList_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles TableList.SelectedIndexChanged
Try
command = New MySqlCommand
dt = New DataTable
adapter = New MySqlDataAdapter
If (conn.State = ConnectionState.Closed) Then
setConnection()
End If
command.Connection = conn
command.CommandText = "SHOW TABLES"
adapter.SelectCommand = command
reader = command.ExecuteReader
'adapter.Fill(dt)
dt.Load(reader)
TableList.DataSource = dt
TableList.DisplayMember = "Tables_in_sampledata" 'What is displayed
TableList.ValueMember = "Tables_in_sampledata" 'The ID of the row
Catch ex As MySqlException
MessageBox.Show("Error1: " & ex.Message)
Finally
reader.Close()
conn.Close()
End Try
End Sub
什么错误的,你得到什么? –