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

Edited 4 Years Ago by Reverend Jim

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

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

This article has been dead for over six months. Start a new discussion instead.