Wednesday, June 20, 2012

Remove duplicates from a datatable..

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);

No comments:

Post a Comment