[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-06-12
4
Medium Priority
?
1,300 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 2000 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

829 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