NerishaB
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
Do you get any error ? Do you get into the procedure ?
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 ?
ASKER
I get the error after it executes line 21 : CustomerIDTextbox.Text = Ds.Tables("Customers").Row s(0).Items ("Customer ID").ToStr ing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, got it now.