0

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
2
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by SQLpower
0

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 by Reverend Jim

0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.