I have a combobox which needs to be populated with data from mysql table, here is my code, I cannot see what's wrong with it? It doesn't throw any error, just comes blank when I run the program.
Dim StrSql As String = "SELECT PaymentID FROM payment_details"
Dim cmd As New MySqlCommand(StrSql, objconnection)
Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd)
Dim dt As New DataTable("Payment_details")
If dt.Rows.Count > 0 Then
cbxPaymentID.DisplayMember = "PaymentID" 'What is displayed
cbxPaymentID.ValueMember = "PaymentID"
cbxPaymentID.DataSource = dt
The ComboBox has Items. What you need to do is create an new Item for each row in your datatable.
If dt.Rows.Count > 0 Then For r = 0 to dt.Row.Count - 1 cbxPaymentID.Items.Add(new ListItem(dt.Row(r).Item("PaymentID")) Next End If
The above is based on standard ASP toolkit ComboBox. Other versions may need different code.