Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 6th, 2009, 01:17 PM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default Regarding data display in windows controls

Hi

I have a windows form with a combobox and listbox.
I have a table name Categories with two columns Category and Subcategory.

Sample data

Category SubCategory

Breakfast Eggmuffin
Breakfast Sausage Muffin
Sandwich Hamburger
Sandwich Cheeseburger

I would like to display the Category in the combobox avoiding the duplicate rows.
Based on the selection of the Category in the combobox, i would like to display the subcategory column in the list box.

It would be nice if anyone could help me with this.

Thanks
Sathi

Last edited by akssmv; May 6th, 2009 at 01:24 PM..
 
Old May 6th, 2009, 01:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hello..

Let's take aside that the table is bad constructed (Categories should be on another table, and this table should had only the id), You could solve your problem using a SELECT DISTINCT category FROM ...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
akssmv (May 7th, 2009)
 
Old May 7th, 2009, 01:04 PM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi

Now I have two tables

1)
Categories

CategoryID --- PK
Category Name

2)
Subcategories

CategoryId----FK
SubCategory

I would like to display the category name from Categories table in combobox.
Based on the selection from the combobox corresponding subcategory from the Subcategories table( here Category id can be duplicate)in the listbox.



Would be nice if anyone could help me in this.
 
Old May 7th, 2009, 11:46 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

akssmv:
Re-structure the Sub-Category Object to the following:

SUBCATEGORY_TBL
SUBCATID PK number,
CATEGORYID FK number, /* Comment: Enforce FK Referential Constraint */
SUBCAT_NAME varchar (80)
Also include for Delete operation, to include Cascade Deletes.

Then use the table in you listbox with the following Query:
select DISTINCT a.CATEGORY_NAME, b.SUBCAT_NAME
from CATEGORY_TBL a, SUBCATEGORY_TBL b
where a.CATEGORYID = b.CATEGORYID
orderby b.CATEGORYID, b.SUBCATID
groupby b.CATEGORYID, b.SUBCATID

Hope this helps.
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.
The Following User Says Thank You to peace95 For This Useful Post:
akssmv (May 8th, 2009)
 
Old May 8th, 2009, 09:19 AM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default

i will try it and let you know, thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Data Will Not Display When I Click On Display Button sprdave BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 12 February 13th, 2011 12:09 AM
Using windows controls in C# cool_hari C# 2 February 14th, 2010 11:02 AM
Windows Custom Controls bmains VB.NET 0 December 21st, 2005 12:17 PM
Display data into windows explorer din_porwal Pro VB.NET 2002/2003 0 August 26th, 2004 02:09 AM
Windows XP controls sangata VS.NET 2002/2003 8 April 12th, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.