Solved

Binding textbox to combobox

Posted on 2010-08-22
6
566 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

19 Experts available now in Live!

Get 1:1 Help Now