How to Check and remove duplicate Row With using DataTable And DataRow?

  • Thread starter Thread starter alianware jack
  • Start date Start date
A

alianware jack

Guest
// the function that i want is when using sqlbulkcopy to
//add data to sql, but on adding to sql the duplicate row
// also will added to sql also, and the below is the code
//that to check duplicate row but it no work.

DataTable ExcelTable;//Table Import From Excel
DataTable gridTable;//Table Import From DataGridView or from sql for compare
Datatable NT;//For New DataTable

foreach (DataRow DR1 in ExcelTable.Rows)
{
bool SameSame = false;
foreach (DataRow DR2 in gridTable.Rows)
{
for (int i = 0; i < ExcelTable.Columns.Count; i++)
{
bool Same = false;
if (DR1 == DR2)
{
Same = true;
}
if (Same)
{
SameSame = true;
}
}
}
//this way i want to check if the row same will remove
//the row and insert data that no duplicate to new datatable
if (SameSame.Equals(true))
{
MessageBox.Show("Same" + DR1.Table.Rows[k][1]);
}
k++;
}

Continue reading...
 
Back
Top