Solved

Binding textbox to combobox

Posted on 2010-08-22
6
569 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Service FileSystemwatcher isse 9 47
EditableGrid how to fetch rows from MySql in php 14 48
Need help with a query 14 40
vb.net dbnull syntax 1 15
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…

697 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