How to update dataset.Tables["tab1"] from records in dataset.Tables["tab2"]?

  • Thread starter Thread starter AndiSHFR
  • Start date Start date
A

AndiSHFR

Hi.

How do i "bulk update" data rows on a dataset table from another one
DataTable?

i have a dataset ds1 with a table "Groups" and a table "newgroupdata"
and i want to update the records in ds1.Tables["Groups"] from the data
in ds1.Tables["newgroupdata"].
Additional i want to insert groups wich are not already in "Groups"
too.

Is this possible.

At the moment i loop thru "newgroupdata" and do a

DataRow[] foundRows = ds1.Tables["Groups"].Select( "Group = '" +
findgroup + "'", "", DataViewRowState.Added );

if(0==foundRows.Length)
{
// Add group to "Groups"
}
else
{
// Update foundRows
}

running this on a table with multiple thousand group records is
horrable slow.
I fear this can only be done in a fast and efficient way using a
database server.
 
If you can, establish the Group column as the PrimaryKey for both
tables. Then you can use Find rather than Select, which is much faster.

If you set the PrimaryKey property for both tables, and if your table
columns are in the same order, you should be able to reduce your code
to something like this:

DataTable groups = ds1.Table["Groups"];
groups.BeginLoadData();
foreach (DataRow row in newgroupdata.Rows)
{
object[] values = row.ItemArray;
groups.LoadDataRow(values, false);
}
groups.EndLoadData();

Would that work for you?
}
 
Back
Top