Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-12
4
Medium Priority
?
1,297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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 tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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