H
headware
I'm attempting to write a function that will overwrite the data for a
certain table in one database with the data from another table (with
the same schema) in another database. Everything seems to work
correctly up until the point at which I call the Update() function on
the data adapter. For some reason after merging the two datasets, the
destination dataset has all the rows from the source table, but
doesn't have any of the row states marked as added. They are all
marked as unchanged, so nothing gets copied over into the destination
table. What am I doing wrong here?
Thanks,
Dave
public void DoCopy(string tableName, string srcPath, string dstPath)
{
//get all data from source table
OleDbConnection srcConn = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=" + srcPath);
OleDbDataAdapter srcAdapter = new OleDbDataAdapter("SELECT * FROM "
+ tableName, srcConn);
DataSet srcDS = new DataSet();
srcAdapter.Fill(srcDS, tableName);
//clear the destination table
OleDbConnection dstConn = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=" + dstPath);
OleDbCommand cmd = new OleDbCommand("DELETE * FROM " + tableName,
dstConn);
dstConn.Open();
cmd.ExecuteNonQuery();
//copy source data into destination table
srcAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
srcAdapter.AcceptChangesDuringFill = false;
OleDbDataAdapter dstAdapter = new OleDbDataAdapter("SELECT * FROM "
+ tableName, dstConn);
dstAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet dstDS = new DataSet();
dstAdapter.Fill(dstDS, tableName);
dstDS.Merge(srcDS);
OleDbCommandBuilder cb = new OleDbCommandBuilder(dstAdapter);
dstAdapter.Update(dstDS.Tables[tableName]);
dstConn.Close();
}
certain table in one database with the data from another table (with
the same schema) in another database. Everything seems to work
correctly up until the point at which I call the Update() function on
the data adapter. For some reason after merging the two datasets, the
destination dataset has all the rows from the source table, but
doesn't have any of the row states marked as added. They are all
marked as unchanged, so nothing gets copied over into the destination
table. What am I doing wrong here?
Thanks,
Dave
public void DoCopy(string tableName, string srcPath, string dstPath)
{
//get all data from source table
OleDbConnection srcConn = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=" + srcPath);
OleDbDataAdapter srcAdapter = new OleDbDataAdapter("SELECT * FROM "
+ tableName, srcConn);
DataSet srcDS = new DataSet();
srcAdapter.Fill(srcDS, tableName);
//clear the destination table
OleDbConnection dstConn = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=" + dstPath);
OleDbCommand cmd = new OleDbCommand("DELETE * FROM " + tableName,
dstConn);
dstConn.Open();
cmd.ExecuteNonQuery();
//copy source data into destination table
srcAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
srcAdapter.AcceptChangesDuringFill = false;
OleDbDataAdapter dstAdapter = new OleDbDataAdapter("SELECT * FROM "
+ tableName, dstConn);
dstAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet dstDS = new DataSet();
dstAdapter.Fill(dstDS, tableName);
dstDS.Merge(srcDS);
OleDbCommandBuilder cb = new OleDbCommandBuilder(dstAdapter);
dstAdapter.Update(dstDS.Tables[tableName]);
dstConn.Close();
}