我是編程新手,我正在研究一個基本的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
什麼錯誤的,你得到什麼? –