mysql表没有得到更新

本文关键字:更新 mysql | 更新日期: 2023-09-27 18:27:02

我正在将数据从SQL服务器复制到mysql。我从sql服务器加载一个表,从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);
    }

mysql表没有得到更新

看看这个SO问题,提问者和你有同样的问题;它是通过删除CCD_ 1命令来解决的。实际上,您已经告诉缓冲区更改已被写回,所以当您进行更多更改时,它们不会被提交。