Solved

Binding textbox to combobox

Posted on 2010-08-22
6
567 Views
Last Modified: 2012-06-22
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

0
Comment
Question by:NerishaB
  • 3
  • 3
6 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33498625
Do you get any error ? Do you get into the procedure ?
0
 

Author Comment

by:NerishaB
ID: 33498682
I do get into the procedure.  The error message I get is: "Object reference not set to an instance of an object.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33498732
And where exactly do you get that error ?
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:NerishaB
ID: 33498756
I get the error after it executes line 21 : CustomerIDTextbox.Text = Ds.Tables("Customers").Rows(0).Items("CustomerID").ToString
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33498785
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
 

Author Closing Comment

by:NerishaB
ID: 33498800
Thanks, got it now.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now