Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 2nd, 2008, 12:04 PM
Registered User
Join Date: Mar 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dataset relations not working like expected

Can someone please tell me if I'm approaching this incorrectly (and if so, suggest a better way) or tell me if I just can't do this at all?

I have 3 tables:

[u]Table 1</u>
tableOneID (PK)

[u]Table 2</u>
tableTwoID (PK)
tableOneID (FK)

[u]Table 3</u>
tableThreeID (PK)
tableTwoID (FK)

I want to be able to display the information in 3 combo boxes, filtered by the selection the 'upper' combo boxes. I have a dataset containing 3 datatables and have created relationships between the tables. It all works great for the first two combo boxes (cboTable_2's data is filtered correctly by selection in cboTable_1) but not for the next combo box - I want cboTable_3's data to be populated based on the selection in cboTable_2.

OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Table_1", conn);
da.Fill(ds, "Table_1");

da = new OleDbDataAdapter("SELECT * FROM Table_2", conn);
da.Fill(ds, "Table_2");

da = new OleDbDataAdapter("SELECT * FROM Table_3", conn);
da.Fill(ds, "Table_3");

DataColumn masterOne = ds.Tables["Table_1"].Columns["tableOneID"];
DataColumn childOne = ds.Tables["Table_2"].Columns["tableOneID"];
DataRelation relation = new DataRelation("RelationMasterChild", masterOne, childOne);

cboTable_1.DataSource = ds;
cboTable_1.DisplayMember = "Table_1.displayString";
cboTable_1.ValueMember = "Table_1.tableOneID";

cboTable_2.Datasource = ds;
cboTable_2.DisplayMember = "Table_1.RelationMasterChild.displayString";
cboTable_2.ValueMember = "Table_1.RelationMasterChild.tableTwoID";

// Now I would assume that I can connect tables 2 and 3 in the same way
DataColumn masterTwo = ds.Tables["Table_2"].Columns["tableTwoID"];
DataColumn childTwo = ds.Tables["Table_3"].Columns["tableTwoID"];
relation = new DataRelation("RelationChildChild", masterTwo, childTwo);

cboTable_3.Datasource = ds;
cboTable_3.DisplayMember = "Table_2.RelationChildChild.displayString";
cboTable_3.ValueMember = "Table_2.RelationChildChild.tableThreeID";
The problem: On load this data is displayed correctly
cboTable_1 filters data in cboTable_2 which in turn filters data in cboTable_3
but when cboTable_1 and/or cboTable_2 selection is changed, cboTable_3 is not updated

Thanks for any input.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
data relations synchronization igalk474 ADO.NET 0 July 21st, 2007 05:36 AM
tables relations helkayal SQL Server 2000 4 April 19th, 2005 03:18 PM
Relations (Urgent plz) Samikaraeen Pro VB.NET 2002/2003 0 July 15th, 2004 03:50 AM
get table-relations from database GARAK ADO.NET 0 February 12th, 2004 07:08 AM
working with data in DataSet fyeojo VS.NET 2002/2003 2 August 26th, 2003 01:17 AM

All times are GMT -4. The time now is 04:22 AM.

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