How to import datarow from one dataset to another?
Posted
by Disciple
on Stack Overflow
See other posts from Stack Overflow
or by Disciple
Published on 2010-03-24T08:19:30Z
Indexed on
2010/03/24
8:23 UTC
Read the original article
Hit count: 167
Hi, I want to copy the row to the new dataset if the previous value in second column isn't the same as the current one (i.e this dataset should have rows with unique values):
DataTable tbl = new DataTable();
DataTable tmpTable = ds.Tables[0];
for( var rowIndex = 0; rowIndex < ds.Tables[0].Rows.Count; rowIndex++ )
{
object value = null;
foreach (DataRow x in tbl.Rows)
{
if (ds.Tables[0].Rows[rowIndex][1] == x[1])
{
value = ds.Tables[0].Rows[rowIndex][1];
break;
}
}
// value already exists
if (value == null)
{
tbl.ImportRow(ds.Tables[0].Rows[rowIndex]);
}
}
How to do this correctly? Maybe one loop instead 2?
© Stack Overflow or respective owner