 |
| 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
|
|
|
|

January 22nd, 2004, 10:53 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

January 23rd, 2004, 05:02 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 24th, 2004, 03:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

January 24th, 2004, 05:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

January 24th, 2004, 09:53 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

January 24th, 2004, 12:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

January 25th, 2004, 01:39 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|
 |