1

我正在将数据从 SQL 服务器复制到 mysql。我从 sql server 加载一个表,从 mysql 加载一个表并复制数据。数据被复制到新表中,但数据库中的表仍然为空。提前致谢。这是我的代码 -

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);

    }
4

1 回答 1

0

看看这个问题,提问者和你有同样的问题;它已通过删除.AcceptChanges();命令解决。实际上,您已经告诉缓冲区更改已被写回,因此当您进行更多操作时,它们不会被提交。

于 2013-08-10T06:42:27.567 回答