I am having issues with ADO.NET 2.0 merging/importing data. I need to update/insert data from one generic table to another table with both tables maintaining an identical schema. The following code works great locally, but does not make changes to the database:
OleDbDataAdapter localDA = loadLocalData();
OleDbDataAdapter hostedDA = loadHostedData();
DataSet dsLocal = new DataSet();
localDA.Fill(dsLocal);
DataSet dsChanges = new DataSet();
hostedDA.Fill(dsChanges);
dsLocal.Tables[0].Merge(dsChanges.Tables[0],false);
localDA.Update(dsLocal.Tables[0]);
The same is true with this code snippet:
OleDbDataAdapter localDA = loadLocalData();
OleDbDataAdapter hostedDA = loadHostedData();
DataSet dsLocal = new DataSet();
localDA.Fill(dsLocal);
DataSet dsChanges = new DataSet();
hostedDA.Fill(dsChanges);
foreach (DataRow changedRow in dsChanges.Tables[0].Rows)
{
if (recordExists(dsLocal.Tables[0], changedRow["ID"]))
{
}
else
{
dsLocal.Tables[0].ImportRow(changedRow);
}
}
localDA.Update(dsLocal.Tables[0]);
When I looked at the RowState property for changed/appended rows they remain "unchanged". I am wanting to avoid data mapping the columns if possible, which is what I may have to do using the NewRow() method and modifying an existing row.