Reputation: 41
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")
da.Fill(dt)
If dt.Rows.Count > 0 Then
cbxPaymentID.DisplayMember = "PaymentID" 'What is displayed
cbxPaymentID.ValueMember = "PaymentID"
cbxPaymentID.DataSource = dt
End If
Upvotes: 0
Views: 134
Reputation: 2563
The ComboBox has Items. What you need to do is create an new Item for each row in your datatable.
something like....
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.
Upvotes: 1