group by in dataview

L

luke

Hello,
I have a dataview that contains about 300k records with 3 cols (read
in from a directory). I need to get the count of rows by col1 and col2
(grouping by col1 and col2). What would be the best way to do it?
Currently, I am sorting them and reading each row and comparing
current row's col1 and col2 with previous row's col1 and col2 and
keeping the total in an arraylist. But this is very slow; I am pretty
new to C#, any help is appreciated.

Thanks.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello,

Unfortunately, you have said nothing about the source of the data. If this
is some kind of database, it would be much better to perform the grouping by
using the database means, such as 'GROUP BY' SQL clause.
 
L

luke

I am rading in filenames from a folder and filling a table out of
their parsed name. Eg, abcde.txt would be put into table where 'a' is
a column, so as b,c,d and e. Now, I need to know how many files that
match columna and columnc exist and get their total. I hope I am being
clear ...

Thanks.
Dmitriy Lapshin said:
Hello,

Unfortunately, you have said nothing about the source of the data. If this
is some kind of database, it would be much better to perform the grouping by
using the database means, such as 'GROUP BY' SQL clause.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

luke said:
Hello,
I have a dataview that contains about 300k records with 3 cols (read
in from a directory). I need to get the count of rows by col1 and col2
(grouping by col1 and col2). What would be the best way to do it?
Currently, I am sorting them and reading each row and comparing
current row's col1 and col2 with previous row's col1 and col2 and
keeping the total in an arraylist. But this is very slow; I am pretty
new to C#, any help is appreciated.

Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Luke,
I hope I am being
clear ...
Not really, are you saying you are parsing each position of the name into a
distinct DataTable column? You do realize that file names can be upto 256
characters so you would need 256 columns?

I would consider defining "parent" tables for your grouping (one for each
grouping), then as I am adding rows to the first DataTable, update the
"parent" datatable with new values. I would also define relationships
between these datatables, so I could use the DataRow.GetChildRows method...

DataTables:
G1 : c1
G2 : c1, c2
G3 : c1, c2, c3

D : c1, c2, c3, c4

c1, c2, c3 & c4 are columns, while G1, G2, & G3 are my grouping tables, & D
is your existing DataTable.

Hope this helps
Jay

luke said:
I am rading in filenames from a folder and filling a table out of
their parsed name. Eg, abcde.txt would be put into table where 'a' is
a column, so as b,c,d and e. Now, I need to know how many files that
match columna and columnc exist and get their total. I hope I am being
clear ...

Thanks.
"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Hello,

Unfortunately, you have said nothing about the source of the data. If this
is some kind of database, it would be much better to perform the grouping by
using the database means, such as 'GROUP BY' SQL clause.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

luke said:
Hello,
I have a dataview that contains about 300k records with 3 cols (read
in from a directory). I need to get the count of rows by col1 and col2
(grouping by col1 and col2). What would be the best way to do it?
Currently, I am sorting them and reading each row and comparing
current row's col1 and col2 with previous row's col1 and col2 and
keeping the total in an arraylist. But this is very slow; I am pretty
new to C#, any help is appreciated.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top