Solved

Bind datatable to combobox (with plain vb code and t-sql)

Posted on 2008-06-12
4
1,289 Views
Last Modified: 2010-04-21
What I want to achieve is quite simple (but I don't know how). I want the user to give the change to pick a customer name with a combo box and show the details (address, phone, ...) in textboxes (or labels). What I don't want is using the build-in custom tools of VB (like bindingsources ..)
I think the best way to reach my goal is:
1. select the customer table in SQL (SELECT * FROM Customers ORDER BY Name)
2. create and open the connection, create and execute the command, use a data-adapter to fill the datatable (this all is not the problem)
3. bind the datatable to the combobox so the pointer in de datatable changes whenever the user chooses another customer (This is the part where I'm stuck).

Any ideas? Or perhaps I'm completely wrong and should I better use data sources, and binding sources?
I'm upgrading a big VB 6 project to VB 2008 and I never used dataenvironments in VB 6 too.

0
Comment
Question by:NoraWil
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Priest04 earned 500 total points
ID: 21770829
If I understood you correctly, you want to display customers data based on the selection in combobox. Then do this:

1) set combobox dataSource property to datatable
2) set DisplayMember property to name of the field that holds customer name (ex: "customerName")
3) bind all other controls (textboxes to datatable

cmbCustomerName.DataSource = dtCustomer;
cmbCustomerName.DisplayMember = "customerName";

txtCustomerAddress.DataBindings.Add("Text", dtCustomer, "CustomerAddress"); // change CustomerAddress to a proper field name

etc

Goran
0
 

Author Closing Comment

by:NoraWil
ID: 31466537
Thanks, actually I only needed the last line of your suggestion an now everythings works as wanted.
0
 

Author Comment

by:NoraWil
ID: 21771417
Thanks for the fast reply. Everything works now.
0
 
LVL 18

Expert Comment

by:Priest04
ID: 21771889
You are welcome.

Goran
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now