Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 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 January 22nd, 2004, 10:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default count child table rows

Dear all, let me ask something fast.
when we wanna count a dataSet Rows created by DataAdapter we use
Code:
dataSet11.Table1.Rows.Count
its ok!
But imagine u've created a realtion using IDE in ur Dataset that [u]PID</u> in Table1 is a perent Col for [u]PID</u> in Table2.
Now u wanna count child table's rows?! what code u'll use?! Thank you.
A problem is hard till it hasnt solved!

Always:),
Hovik Melkomian.
__________________
Always,
Hovik Melkomian.
 
Old January 23rd, 2004, 05:02 PM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DataSet dsData;

dsData.Tables[0].ChildRelations["RelationName"].ChildTable.Rows.Count;

It's important for us to explain to our nation that life is important. It's not only life of babies, but it's life of children living in, you know, the dark dungeons of the Internet."— George W. Bush - Arlington Heights, Ill., Oct. 24, 2000
 
Old January 24th, 2004, 03:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

tnx for ur reply dear:
but its doesnt count the related rows in detail! I could count the whole rows before. my problem is : counting related rows in [u]Detail Table</u> not the whole!

hope to hear new ideas.

Always:),
Hovik Melkomian.
 
Old January 24th, 2004, 05:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Melvik,

You can take a look at the GetChildRows method of the DataRow object. It returns an Array of DataRows that are related to the original DataRow. You can then use the Length property of the Array to get the number of items.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 24th, 2004, 09:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Ok tnx it works now, but working witgh this is pretty hard;) do u have any other idea to work with Data in [u]realed table</u>?!

Always:),
Hovik Melkomian.
 
Old January 24th, 2004, 12:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, true. It's not as easy or intuitive as you'd like. Then again, it is a *lot* easier than the "old skool" data shaping that Microsoft had for things like this in ADO ;)

Usually I don't use these kind of relations in my dataset. If acceptable (performance wise), I fire a sub query for the related records. Just pass a simple select statement with the ID of the parent record.

However, when you're displaying lots of parent record with their child records (like a DataGrid that displays a nested grid with the child records), this may not be applicable (too many database operations). In that case, using relations is a good way to go. Alternatively, you can create a global DataSet object, store a few DataTables in them and use some filtering techniques to get the related records. But this is, IMO, about as difficult as using the DataRelations ;)

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 25th, 2004, 01:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear Imar:
tnx for ur comments. As I said its not easy to manage, but better than ADO as u said. So i guess using this way would be not better but good. I guess using ur second way (get child info by passing Master ID) would make LAN trafic. So i pefer to manage it once but use it many. anyway tnx for reply & ...


Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using axis instead of count? Counting child nodes. dep XSLT 1 January 17th, 2007 11:27 AM
How to count the child node suri_1811 XSLT 6 November 10th, 2006 04:51 PM
count of rows ashokparchuri ADO.NET 3 April 19th, 2005 11:19 AM
count the number of rows in the table crmpicco Javascript How-To 4 February 2nd, 2005 12:58 AM
count or show child table's rows melvik ADO.NET 0 January 22nd, 2004 11:00 AM





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