By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.