Binding textbox to combobox

Hi, i have a form  that contains a combobox that i have bound to a datasource.  Now, I also dragged another field from the datasource, but I want this field to change whenever the user selects a value from the combobox.  I have the attached code, but it does not seem to work.  Any deas?
Private Sub CustomerRefComboBox_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerRefComboBox.SelectedIndexChanged
        Dim Con As New MySqlConnection
        Dim Com As New MySqlCommand
        Dim Da As New MySqlDataAdapter
        Dim Ds As New DataSet
        Dim Dt As New DataTable
        Dim CustomerRef As String
        Dim sql As String

        CustomerRef = CustomerRefComboBox.Text

        sql = "Select * from Customers where Name ='" & CustomerRef & "'"
            Con = GetConnection()
        Try
            Con.Open()
            Com.Connection = Con
            Com.CommandText = sql
            Da.SelectCommand = Com
            Da.Fill(Dt)

          CustomerIDTextBox.Text = Ds.Tables("Customers").Rows(0).Item("CustomerID").ToString()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Open in new window

NerishaBAsked:
Who is Participating?
 
DhaestConnect With a Mentor Commented:
I see it now. You perform a fill directly on your datatable-level, not on dataset-level. (Da.Fill(Dt))

Try this:
CustomerIDTextbox.Text = dt.Rows(0).Items("CustomerID").ToString
0
 
DhaestCommented:
Do you get any error ? Do you get into the procedure ?
0
 
NerishaBAuthor Commented:
I do get into the procedure.  The error message I get is: "Object reference not set to an instance of an object.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
DhaestCommented:
And where exactly do you get that error ?
0
 
NerishaBAuthor Commented:
I get the error after it executes line 21 : CustomerIDTextbox.Text = Ds.Tables("Customers").Rows(0).Items("CustomerID").ToString
0
 
NerishaBAuthor Commented:
Thanks, got it now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.