473,379 Members | 1,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Fill text box after selecting value in combobox

Hi,
Beginning to learn Visual Basic 10.
Experienced user of VB 6 it now is time to learn the modern approach...

Case:
Table 'Customer' in SQL Server, Fields are 'Name' and 'Adress'

VB Program starts and loads all Customer Names in combo box and all details in a DataGrid.
This is already working.

Then I want to display the Adress when selecting a Name in the combo box.

And this I can't get to work.

Coding (The part that is working):

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private SQLCon As New SqlConnection("Data Source=zzz;Initial Catalog=yyy;Integrated Security=SSPI")
  3.     Private da1 As New SqlDataAdapter("SELECT * FROM Customers", SQLCon)
  4.     Private ds As New DataSet
  5.     Private cmb As New SqlCommandBuilder(da1)
  6.  
  7.     Private MySQL_Cmd As New SqlCommand
  8.     Private sSQLQuery As String
  9.     Private MySQL_DA As New SqlDataAdapter
  10.     Private My_DS As New DataSet
  11.  
  12. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  13.    Try
  14.  
  15.    da1.Fill(ds, "Customers")
  16.    DataGrid.DataSource = ds.Tables("Customers")
  17.  
  18.  
  19.    sSQLQuery = "SELECT DISTINCT C_Name FROM Customers"
  20.    MySQL_Cmd = New SqlCommand(sSQLQuery, SQLCon)
  21.    MySQL_DA = New SqlDataAdapter(MySQL_Cmd)
  22.    MySQL_DA.Fill(My_DS, "Tab1")
  23.  
  24.    Cbx_Name.Items.Clear()
  25.    Cbx_Name.DisplayMember = "C_Name"
  26.    Cbx_Name.ValueMember = "C_Name"
  27.    Cbx_Name.DataSource = My_DS.Tables(0)
  28.    Cbx_Name.SelectedIndex = 0
  29.  
  30.    Catch ex As Exception
  31.             MessageBox.Show(ex.Message)
  32.    End Try
  33. End Sub
  34.  
  35. '+++++++++++++++
  36. THE PART THAT DOES NOT WORK
  37. '+++++++++++++++++++++++++++
  38.  
  39. Private Sub Cbx_Name_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles Cbx_Name.SelectedIndexChanged
  40.  
  41. Try
  42.   sSQLQuery = "SELECT * FROM Customers WHERE C_Name = '" & Cbx_Name.SelectedValue & "'"
  43.  
  44.   MySQL_Cmd = New SqlCommand(sSQLQuery, SQLCon)
  45.   MySQL_DA = New SqlDataAdapter(MySQL_Cmd)
  46.   MySQL_DA.Fill(My_DS, "Tab2")
  47.  
  48.  
  49.   Dim dr As DataRow = My_DS.Tables(1).Rows(0)
  50.  
  51.   Text_Adress.Text = dr("C_Adress").ToString
  52.  
  53.   Catch ex As Exception
  54.         MessageBox.Show(ex.Message)
  55.   End Try
  56.  
  57. End Sub
  58. End Class
Sep 17 '13 #1
0 1967

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Niels | last post by:
Hello, I'm trying to get te index of a specific text in a ComboBox. The ComboBox is filled by searching for filenames in a directory. The text of the last item selected in the ComboBox is saved in...
4
by: L Mehl | last post by:
Using VBA, when assigning values to variables from textboxes or comboboxes. the property "Text" or "Value" does not capitalize, yet the assignment works. In addition, appending "Text" or "Value"...
3
by: gasturbtec | last post by:
i'm using access 2000 and have a form in which users can select reports with check boxes and click a print button to print out the selected reports. what i want to do now is place a text box on the...
3
by: | last post by:
Hello, I try to format the text of a combobox with DropDownStyle "DropDown". I just mean the text which is displayed when the combobox isn't touched. Usually it displays the ToString() method of...
1
by: Martin | last post by:
Dear Group Sorry for bothering you again but I need expert advice on this. I have placed a HTML textbox on my aspx form and converted it to run as a server control. At some point in my code I...
0
by: NET Developer | last post by:
I have dropdownList boxes that are bound to a function that populates them with different values for the text and value properties. But when an item is selected from the list, both the text and value...
7
by: Nikolay Petrov | last post by:
How to enumerate and fill text boxes in an WebBrowser control? TIA
3
by: Roger | last post by:
I want to fill a combo box with a Text value to show like name, but when it is selected I want to get the say SS# or Emp #. I will be filling this in manually how should I go about this. I...
1
by: Archanak | last post by:
Hi, I have one common text box and i have to pass that textbox value to 2 forms.(what ever user enters in that text box) I don't know how to write javascript to get that text box value and pass...
1
by: libish | last post by:
hi all .. can any one help me suggesting a way to clear the text box value when controll is at the text box.? here i got a textBox, initially i got some text in it, while i do some edition in...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.