-
May 3rd, 2012, 04:26 PM
#1
Thread Starter
Member
How to break down a DataTable into groups of rows(ones with same traits under Column
Hi guys,
I have a Datatable with one column of the table being 'PartNum(product part number)'. I used EntriesTable.DefaultView.Sort = "PartNum ASC"
to sort the whole Table, with respect to the information in this column. Now I'm just trying to further sort the table by grouping rows that have same info under that column together and do something to each of such groups. but I'm kinda stuck here.
I'm thinking of creating some sub-DataTables out of the original one and have these sub-tables to hold those rows with same info under "PartNum".
Does anyone have ideas how to do that? maybe with DataReader or DataView , I think??
-
May 3rd, 2012, 06:22 PM
#2
Re: How to break down a DataTable into groups of rows(ones with same traits under Col
Sounds like you want an aggregate. What exactly do you want to do to each group ?
-
May 3rd, 2012, 09:32 PM
#3
Re: How to break down a DataTable into groups of rows(ones with same traits under Col
If you want grouping, then that can be done with the "Select" statement that loads the datatable.
something like,
Code:
"Select PartNum, Sum( cost ) from YourTableName Group By PartNum Order By PartNum"
-
May 4th, 2012, 12:16 AM
#4
Re: How to break down a DataTable into groups of rows(ones with same traits under Col
It sounds like all you need is a DataView. Simply create a new DataView for that DataTable, or use the DefaultView if appropriate, and then set the Filter property. That won't affect the DataTable itself but the DataView will hide all records that do not match the condition. The Select method of the DataTable can work in a similar way but return an array of DataRows instead.
-
May 4th, 2012, 09:59 AM
#5
Thread Starter
Member
Re: How to break down a DataTable into groups of rows(ones with same traits under Col
Thanks for the replies. After grouping by this trait, there's a third column that I need to check and combine some rows with respect to the info under that third column.
But this PartNum column has higher priority so i want to do it first
-
May 4th, 2012, 10:04 AM
#6
Re: How to break down a DataTable into groups of rows(ones with same traits under Col
We need to know whether you want to aggregate or partition the data in order to describe how to do it. It sounded to me like you wanted to partition originally but now it seems like you might want to aggregate. Please provide a full and clear description of exactly what you want to achieve.
-
May 7th, 2012, 04:16 PM
#7
Thread Starter
Member
Re: How to break down a DataTable into groups of rows(ones with same traits under Col
Sorry about the confusion. Below are some samples from my table to illustrate what i want to do
PartName|Reference Designator| PartNum | Manufacturer (and few other information..)
x|C201 |02300877 |Samsung |….
x|C201 |02300877 |Toshiba |….
x|C207 |02301165 |....
x|C209 |02301165 |….
x|C213 |02300877 |Samsung
x|C213 |02300877 |Toshiba
x| C303 |02301163
x| C305 |02301163
x|C606 |02300877 |Samsung
x|C606 |02300877 |Toshiba
x|C708 |02301165
x|C712 |02301163
Primarily I'm trying to group entries with same PartNum together. This part can be done, as jmcilhinney suggested, by using DataView(DefaultView) to seperate the table into many(3,for the above sample's case)sub-tables. After I got the sub-tables, I want to go into each subtable and combine similar entries, as they only differ by Reference Designator now(I'll worry about difference in Manufacturer info later). Finally I would join everything back to one big DataTable now that they are properly sorted, grouped and combined. So part of the final Table would look like
x| C201,C213,C606,C619 |02300877
x| C303, C305,C712 |02301163
x| C207, C209, C708 |02301165
I think the confusion about whether I want to partition or aggregate arose as i only mentioned half of what I'm trying to do. Suggestions on the first half to partition or the second part to combine similar entries are all appreciated. Thanks guys.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|