[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Binding textbox to combobox

Posted on 2010-08-22
6
Medium Priority
?
575 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

831 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