I´m trying to get my DataAdapter to update/insert new values to my table from another database (same table but different values) It should just copy the values from DB1 and insert/update them in DB2. I´m getting no compilation errors and the DataTables seems to have the correct values. But nothing gets updated or inserted.
So it should Fill a Datatable (dataTable1) from my database (DB1), then set all rows to be modified and insert them into DB2 But, it wont work.
DataTable dataTable1 = new DataTable("counters");
string command = "SELECT * FROM counters;"; // same layout and name on both tables
using (MySqlConnection connectionFrom = new MySqlConnection(constringfrom)) // DB1
{
MySqlDataAdapter dataAdapter1 = new MySqlDataAdapter(command, connectionFrom);
dataAdapter1.Fill(dataTable1);
}
using (MySqlConnection ConnectionTo = new MySqlConnection(constringto)) // DB2
{
MySqlDataAdapter dataAdapter2 = new MySqlDataAdapter(command, ConnectionTo);
MySqlCommandBuilder cmb2 = new MySqlCommandBuilder(dataAdapter2);
dataAdapter2.UpdateCommand = cmb2.GetUpdateCommand();
dataAdapter2.InsertCommand = cmb2.GetInsertCommand();
foreach (DataRow r in dataTable1.Rows)
{
r.SetModified(); // just for testing purposes..
}
dataAdapter2.Update(dataTable1); // Correct values but no update to the DB :(
}
Console.WriteLine("Updating..... DONE"); // well... no