?
Solved

Syntax for using data relations

Posted on 2006-04-03
12
Medium Priority
?
214 Views
Last Modified: 2012-06-27
I've got a data set with two tables and a one to many relationship between them, all generated in the VS2005 Dataset designer.  In the vb code, I can access the tables and their adapters fine.

I'd like to get the child rows associated with a parent row, and then total values in the child row.  But first thing first, just get the collection of child rows.

In my newbie-ness, I got as far as this:  
 
Dim wrkRows As DataRowCollection
        wrkRows = wrkTable.FindByID(wrkID).GetChildRows(            <-- asks for name of datarelation here

but I don't know how to call up the name of the data relation that apparently is supposed to go into the parameters for the .GetChildRows method.   It doesn't seem to come up through intellisense if I type in the name of the dataset there.

Am I supposed to type the name in without the intellisense?  Is the name in the intellisense for the dataset, but under another variable?  Should it be there, and because it's not it indicates I've not completed the relation properly?  Am I approaching this whole thing incorrectly?

Any guidance on this would be appreciated.

Thanks!
0
Comment
Question by:codequest
  • 7
  • 4
12 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1200 total points
ID: 16366750
Did you define a DataRelation for the DataSet?

Example:

  Dim table1 As DataTable = ds.Tables("Table1")
  Dim table2 As DataTable = ds.Tables("Table2")
  ds.Relations.Add("Table1_Table2", table1.Columns("PrimaryKey"), table2.Columns("PrimaryKey"))

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16366992
Thanks for the input.  Well, I built the relation in the XML Schema designer for the dataset.  I'll try building it in code per your example and see what shows up...it's there when I go back and look at it.  I'm surprised the schema designer didn't add it to the ds.Relations collection...any clue as to whether it was supposed to?
0
 
LVL 9

Assisted Solution

by:Naveen Swamy
Naveen Swamy earned 800 total points
ID: 16367954
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1200 total points
ID: 16370337
In the schema designer, is there a relationship defined between the tables?

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16374186
navstar16:  thanks, those are useful.

Bob:  Yes, there appears to be.  In the Dataset designer there's an arrow between the two tables.  When I select Edit on the arrow it shows the configuration box for the relation...I'm a newbie in SQL but know some Access and it all looks normal.   There's XML in the schema file (which I'm unfamiliar with) that seems to have enough info to represent the relation...and the same name that's shown in the designer for the relation.
 

0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1200 total points
ID: 16374200
How are you filling the DataSet?

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16375832
Both tables are filled using tableadapters.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1200 total points
ID: 16380479
What is the result of DataSet.Relations.Count then?

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16412681
Count = 1

So perhaps I just need the right syntax.
0
 
LVL 2

Author Comment

by:codequest
ID: 16412827
Which I think I figured out...and am now testing....

I guess I was looking for intellisense access to the relations by name, which I couldn't find.  Settling for access by literal or index number.
0
 
LVL 2

Author Comment

by:codequest
ID: 16414137
Yep, works, so I'll split points here.  Thanks for the prompting and coaching!
0
 
LVL 2

Author Comment

by:codequest
ID: 16414149
Key to syntax was realizing that      parentrow.childrelations(relation)   returns an array of rows, not a collection
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

594 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