Hello guys,

I am trying to dynamically update a combobox using mysql database, however I get the Error Catch Message.

Any help would appriciated.

    Private Sub cmbName_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbName.DropDown
        Try
            dbCon = New MySqlConnection("SERVER=localhost;DATABASE=test;")

            strQuery = "Select name from customer_details"


            cmbName.Items.Clear()

            If DR.HasRows = 0 Then

            Else
                cmbName.Items.Add(DR(0).ToString)
            End If

            SQLCmd = New MySqlCommand(strQuery, dbCon)
            DR = SQLCmd.ExecuteReader
            dbCon.Open()



            DR.Close()
            dbCon.Close()
        Catch ex As Exception
            MsgBox("Failure to communicate!" & vbCrLf & vbCrLf & ex.Message)
        End Try
    End Sub

Execute the SQL reader before you check if there are any rows, then step through the records and populate the combobox as in

Dim dr As SqlDataReader = SQLcmd.ExecuteReader

If dr.HasRows Then
    Do While dr.Read()
        cmbName.Items.Add(dr(0))
    Loop
Else
    MsgBox("no records")
End If

Ah, I must've been too sleepy. Thank you once again. Eventhough I changed it, it doesn't work...

try my code but change one line to

cmbName.Items.Add(dr(0).ToString)

Yeah did it that way, still I just receive the error catch message....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.