gpt4 book ai didi

c# - mysql表没有得到更新

转载 作者:行者123 更新时间:2023-11-30 23:15:18 25 4
gpt4 key购买 nike

我正在将数据从 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);

}

最佳答案

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

关于c# - mysql表没有得到更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18159346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com