Solved

Binding textbox to combobox

Posted on 2010-08-22
6
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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