471,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

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

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.

Jan 12 '06 #1
1 1680
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?
}

Jan 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.