We help IT Professionals succeed at work.
Get Started

C# DataView, DataSet (or other) to do a "group by" filter

trippy1976
trippy1976 asked
on
5,256 Views
Last Modified: 2013-12-17
I am loading a CSV file into DataSet object.  Then putting the data into a DataView so I can easily sort it.  

That's sweet and easy.  But my ultimate goal is to remove any rows where the GUID only occurs in the data set one time.  I tried a filter like this:

sortedData.RowFilter = "COUNT(GUID) > 2 group by GUID";

But of course that does not work.  I think the COUNT thing is okay, but what I want is like on a SQL query for it to group by GUID.  This would naturally remove any records which have a GUID that does not appear more than twice in the data.

Is there a good way to do this?  Or am I going to be forced to loop through the data set after it's sorted, manually deleting the rows I don't want?
// Sort it by GUID then Source
                DataView sortedData = this.csvDATA.Tables[0].DefaultView;
                sortedData.Sort = "GUID,SOURCE ASC";

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE