1

I am copying data from SQL server to mysql. I load a table from sql server and a table from mysql and copy the data over. The data is getting copied into the new table but the tables in database remains empty. thanks in advance. Here is my code -

private void WriteTable(DataTable table, string tablename)
    {
        long maxid=0;
        MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from " + tablename, mysqlConn);
        MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd);
        DataTable dest = new DataTable();
        adapter.Fill(dest);
        txtMessages.Text += table.Rows.Count.ToString()+"\r\n";
        foreach (DataRow row in table.Rows)
        {
            DataRow newrow = dest.NewRow();
            newrow.BeginEdit();
            foreach (DataColumn col in table.Columns)
            {
                newrow[col.Caption] = row[col.Caption];
            }
            newrow.EndEdit();
            dest.Rows.Add(newrow);
            maxid = long.Parse(row["RowID"].ToString());
            txtMessages.Text += maxid.ToString() + "\r\n";
            SetRowID(tablename, maxid);
        }
        MySql.Data.MySqlClient.MySqlCommandBuilder builder = new MySql.Data.MySqlClient.MySqlCommandBuilder(adapter);
        adapter.DeleteCommand = builder.GetDeleteCommand();
        adapter.InsertCommand = builder.GetInsertCommand();
        adapter.UpdateCommand = builder.GetUpdateCommand();
        dest.AcceptChanges();
        adapter.Update(dest);

    }
melodiouscode
  • 2,105
  • 1
  • 20
  • 41
Opax Web
  • 848
  • 3
  • 12
  • 25
  • possible duplicate of [Update using MySqlDataAdapter doesn't work](http://stackoverflow.com/questions/15259400/update-using-mysqldataadapter-doesnt-work) – melodiouscode Aug 10 '13 at 06:41

1 Answers1

0

Take a look over at this SO question the asker had the same problem as you; it was resolved by removing the .AcceptChanges(); command. In effect you have already told the buffer that changes have been written back, so when you then make more they do not get committed.

Community
  • 1
  • 1
melodiouscode
  • 2,105
  • 1
  • 20
  • 41