Remove duplicates from a datatable..

Sabarimahesh
Posted by Sabarimahesh under C# category on | Points: 40 | Views : 2092
using System.Data;
using System.Linq;
DataTable dt = ds.Tables[0];
DataView dv = new DataView(dt);
string cols = string.Empty;
foreach (DataColumn col in dt.Columns)
{
if (!string.IsNullOrEmpty(cols)) cols += ",";
cols += col.ColumnName;
}
dt = dv.ToTable(true, cols.Split(','));
ds.Tables.RemoveAt(0);
ds.Tables.Add(dt);

Comments or Responses

Login to post response