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
Solved

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

Posted on 2008-06-12
4
1,293 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
VB.NET Repostiory Pattern 7 49
VB.NET 2008 Publish Error 2 32
How do sunrise and sunset times change with altitude 14 35
Groupbox Control ? 2 17
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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