This article mainly introduces the method of DataTable de-weight in C #, through two different methods to compare and analyze the technique of DataTable de-heavy, very practical value, the need for friends can refer to the following
Here are two main ways of doing this:
1 database directly removes duplicates
SELECT DISTINCT * FROM table name
2 working directly on a DataTable
DataTable dt=db. GETDT ("SELECT * from table name");//Get Datatabledataview DV = new DataView (dt);//Virtual view, I think so. DataTable DT2 = dv. ToTable (True, "name,age,hobby");
This time, DT2 is removing the duplicate lines.
Here's an explanation: DV. ToTable (True, "name,age,hobby");
First parameter, true to remove duplicates, false not to remove
The second parameter, see meaning can understand, you need to show the field, I show here "Name,age,hobby"
Method of DataTable de-weight in C #