Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

How to create a datasource to a combobox?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vanessa - 06 Mar 2008 19:43 GMT
Hi all!

I need do create a combobox just with related rows, and they are in a third
table.

Explaining better: I have a table of salesmen, another of customers and
another one with relationship of salesmen X customers. When I select a
salesman, I want only to show the customers that are related to him.

Does it have a way to create one datatable with the customers related to the
salesman to be used in the datasource of the combobox?

Thank you in advance,
Vanessa
dlm@bypsoft - 07 Mar 2008 08:00 GMT
Hi Vanessa,

your problem is a common problem and I'm wonderng that nobody has responded to you. The solution is simple, if I got it correctly.
Let's say you want to have two combo boxes, one with Salesman's and the second one with Customers which belong to the selected salesman in the first combo box. To fullfill this you will need one DataSet called dsSales. For both ComboBexes you will need one BindingSource for each: bindingSourceSalesman and bindingSourceSalesmanCustomers. Your dataset has to contain two data tables tableSalesman and tableSalesmanCustomers where salesman has been filld from sql statement like
"select salesmanId, salesmanName from salesman"
and the second one
"select salesmanid, customerId, customerName from customers c inner join salesmanXcustomers s on c.salesmanId = s.salesmanId"
So, after filling your DataTables and adding them to the dsSales you need to add foreign key relations between those two DataTables on a salesmanId (note that you have it on both tables). Assume name of this relations is "FK_Salesman_X_Customers"

Next steps are related to the BindongSources. We are telling them what and how to bind.
bindingSourceSalesman.DataSource = dsSales; //your DataSet
bindingSourceSalesman.DataMember = "tableSalesman"; //name of the table - string

The second one, bindingSourceSalesmanCustomers will have as DataSource our bindingSourceSalesman, not our DataSet dsSales and DataMember will not be set to any table but to the foreign key relations name you set between these two tables.

bindingSourceSalesmanCustomers.DataSource = bindingSourceSalesman;
bindingSourceSalesmanCustomers.DataMember = "FK_Salesman_X_Customers";

On this way, once you are changing selection to comboBoxSalesman available values will be updates in comboBoxSalesmaCustomers.

Hope this helps.
Best regards,

Best regards,
dlm@bypsoft
Compare SQL Server, MySQL and Oracle for free - DBTyP.NET
www.bypsoft.com

> Hi all!
>
[quoted text clipped - 10 lines]
> Thank you in advance,
> Vanessa
Vanessa - 07 Mar 2008 12:46 GMT
Thank you very much! It help me a lot!

Vanessa

> Hi Vanessa,
>
[quoted text clipped - 38 lines]
> > Thank you in advance,
> > Vanessa

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.