Link to home
Start Free TrialLog in
Avatar of NerishaB
NerishaBFlag for South Africa

asked on

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

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Do you get any error ? Do you get into the procedure ?
Avatar of NerishaB

ASKER

I do get into the procedure.  The error message I get is: "Object reference not set to an instance of an object.
And where exactly do you get that error ?
I get the error after it executes line 21 : CustomerIDTextbox.Text = Ds.Tables("Customers").Rows(0).Items("CustomerID").ToString
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, got it now.