void RemoveDuplicates(System.Data.DataTable dataTable)
{
System.Data.DataTable duplicateTable = dataTable.Clone();
System.Data.DataColumn[] primaryKey = new System.Data.DataColumn[duplicateTable.Columns.Count];
duplicateTable.Columns.CopyTo(primaryKey, 0);
duplicateTable.PrimaryKey = primaryKey;
System.Data.DataRow[] dataRows = new System.Data.DataRow[dataTable.Rows.Count];
dataTable.Rows.CopyTo(dataRows, 0);
foreach (System.Data.DataRow dataRow in dataRows)
if (dataRow.ItemArray[9].ToString() != "")
{
dataRow.ItemArray[9] = "2";
if (duplicateTable.Rows.Contains(dataRow.ItemArray))
dataTable.Rows.Remove(dataRow);
else
duplicateTable.Rows.Add(dataRow.ItemArray);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment