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

Probelm with DataSet Merge and GetChanges

P: n/a
All,

I'm having an issue merging datasets. It seems everytime I peform a
merge of new data on existing data all of the rows of the existing
data are modified even if the new data does not change. Is this
normal behavior?

Here is an example of what I'm finding:

DataSet dsExisting = new DataSet();
DataSet dsNew = new DataSet();

dsExisting.Tables.Add();
dsExisting.Tables[0].Columns.Add("c1");
dsExisting.Tables[0].Columns.Add("c2");
DataRow newRow = dsExisting.Tables[0].NewRow();
newRow[0] = "rwc1";
newRow[1] = "r1c2";
dsExisting.Tables[0].Rows.Add(newRow);
DataColumn[] pkey = new DataColumn[1];
pkey[0] = dsExisting.Tables[0].Columns[0];
dsExisting.Tables[0].PrimaryKey = pkey;
dsExisting.AcceptChanges();

Console.WriteLine("Existing");
foreach (DataRow row in dsExisting.Tables[0].Rows)
{
for (int i = -0; i < row.ItemArray.Length; i++)
{
Console.Write(row[i].ToString() + ":" +
row.RowState + "\t");
}
Console.Write("\r\n");

}

dsNew.Tables.Add();
dsNew.Tables[0].Columns.Add("c1");
dsNew.Tables[0].Columns.Add("c2");
newRow = dsNew.Tables[0].NewRow();
newRow[0] = "rwc1";
newRow[1] = "r1c2";
dsNew.Tables[0].Rows.Add(newRow);
dsNew.AcceptChanges();

Console.WriteLine("New");
foreach (DataRow row in dsNew.Tables[0].Rows)
{
for (int i = -0; i < row.ItemArray.Length; i++)
{
Console.Write(row[i].ToString() + ":" +
row.RowState + "\t");
}
Console.Write("\r\n");

}

dsExisting.Merge(dsNew, true);

Console.WriteLine("Merged");
foreach (DataRow row in dsExisting.Tables[0].Rows)
{
for (int i = -0; i < row.ItemArray.Length; i++)
{
Console.Write(row[i].ToString() + ":" +
row.RowState + "\t");
}
Console.Write("\r\n");

}

Console.WriteLine("Hit Enter");
Console.ReadLine();

Aug 8 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.