Solved

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

Posted on 2008-06-12
4
1,292 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting multiple values from a dataset ASP.NET(VB) 3 49
VB.NET 2008 (3.5 Framework) Remove all items from List 3 22
Error handling in asp.net site 5 25
Sql server insert 13 28
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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