Copy DataTable into a Ms Access table

  • Thread starter Thread starter ziocantante
  • Start date Start date
Z

ziocantante

Guest
I need to copy a DataTable inside another table (MS Access) which has the same structure. I did this:

DataTable dtBit = new DataTable();
dtBit.TableName= "Macchine_Bit";

using (OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Macchine_Bit] ORDER BY [FIELD_ID]", cnn))
{
using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
{
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(dtBit = new DataTable());
}
}




When I got my DataTable, I open a connection to another mdb file and try to put the contents of dtBit table into another:


cnn.ConnectionString = String.Format(myConnectionString, mdbCopyName);
cnn.Open();

using (OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM [Macchine_Bit]", cnn))
{
OleDbCommandBuilder cb = new OleDbCommandBuilder(a);
a.MissingSchemaAction = MissingSchemaAction.AddWithKey;
a.InsertCommand = cb.GetInsertCommand();
a.DeleteCommand = cb.GetDeleteCommand();
a.UpdateCommand = cb.GetUpdateCommand();
a.TableMappings.Add("Macchine_Bit", "Macchine_Bit");

DataTable dtBit2 = new DataTable();
a.Fill(dtBit2);

dtBit2.Merge(dtBit);
a.Update(dtBit2);
}


Basically no rows are written. What's wrong with my code? I got non error

Continue reading...
 
Back
Top