c# () method Remove duplicates of table
() method and its overload:
()
Create and return a new DataTable based on the rows in the existing DataView.
(String)
Create and return a new DataTable based on the rows in the existing DataView. The parameter String is the name of the returned DataTable. The output table is the same as the columns of the input table and cannot be customized.
(Boolean,String[])
Create and return a new DataTable based on the rows in the existing DataView. If the parameter Boolean is true, it means that there are rows with different values of columns. If it is false, it will not be knocked out, and the default is false.
The returned column can be customized, and the array String[] is a collection of the returned columns.
example:
DataView dv = new DataView(table); table = (true, "ID"); //Deduplication, return to the ID column in the original table //table=(true,"ID","name"); //returnID and nameTwo columns
(String,Boolean,String[])
Create and return a new DataTable based on the rows in the existing DataView. One more parameter than 3, you can define the name of the return table.
C# DataTable merge and remove duplicate data
The code is as follows:
merge
/// <summary> /// Merge the same datatable data structure/// </summary> public DataTable Mergedata(){ DataTable data = new DataTable(); DataTable deptdata = new DataTable(); data=("select * from T1", null); deptdata=("select * from T2", null); (deptdata, true); return data; }
Exclude duplicate data
/// <summary> /// Remove datatable duplicate data /// </summary> public DataTable distinctdata() { DataTable data = new DataTable(); DataTable distinctdata = new DataTable(); List<string> datarowlist = new List<string>(); string[] datarow; foreach (DataColumn row in ) //Transf the table header { (()); } datarow = (); DataView dv = new DataView(data); distinctdata = (true, datarow); //Filter all fields of the table, true means using distinct method return distinctdata; }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.