473,699 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fill text box after selecting value in combobox

1 New Member
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 1983

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

Similar topics

3
6686
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 a textfile in the OnExit Event of the Mainform. While loading the Mainform I want the text that was saved in the file to be compared with the items in the ComboBox ad get the index of the found item, so that I can set it as selected. I...
4
1813
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" to the control name is not even necessary to make the assignment work. Examples: strStringValue1 = Me.cmbCombo1.value
3
3850
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 form where the user can put the number of copies they want to print. i want to take that value and loop through my print code the number of time = to the text box value
3
6019
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 the SelectedItem. But I want to override the it. Overriding the ToString() of the class of the SelectedItem doesn't help because I can't touch the class. Maybe I have to rewrite the WndProc WM_PAINT. Whatever, I just need an idea. ... Thanks!
1
6707
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 assign a value to this textbox using Javascript with 'Form1.TextBox1.Value = "Hello"' But when I want to read the value of this Textbox later on using VB with 'MyVar = TextBox1.Text' it returns nothing.
0
936
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 properties are the same, Why? Below is a sample of the code '************************************************************************************* 'Load the Status Code Drop Down bo...
7
1663
by: Nikolay Petrov | last post by:
How to enumerate and fill text boxes in an WebBrowser control? TIA
3
1495
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 know combo1.items.add(Item) But what I don't get is how to assign both the text and value at the same
1
1784
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 it to both forms!! How to get the text box value and pass it to both the forms? With regards
1
1711
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 that text, the text box is suppose to be cleared. what should i do for clearing the textBox? which event is happening while we do some edition in the text box?
0
8630
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4638
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.