gpt4 book ai didi

c# - Datagridview 更新到 DB mysql 错误 ""并发冲突 : the updatecommand affected 0 of the expected 1 records""

转载 作者:行者123 更新时间:2023-11-30 22:59:09 32 4
gpt4 key购买 nike

如何从 Datagridview c# 更新数据库?我的项目是在数据库中加载数据表。但无法更新到数据库中

加载数据按钮

private void button2_Click(object sender, EventArgs e)
{
string connectionString;

connectionString = "Server=localhost;User Id=root; Password=1234; Database=db2; Pooling=false;CharSet=tis620;";
connection = new MySqlConnection(connectionString);
sda = new MySqlDataAdapter("Select * from data Where Id = '" + comp.Text.Trim() + "'", connection);

dt = new DataTable();
sda.Fill(dt);
Table1.DataSource = dt;

}

和更新按钮

private void button3_Click(object sender, EventArgs e)
{

cmdbl = new MySqlCommandBuilder(sda);

sda.Update(dt);//error" concurrency violation: the updatecommand affected 0 of the expected 1 records"
dt.AcceptChanges();
MessageBox.Show("Save data complete");

}

我关注这个剪辑 Insert,Delete and Update data in database from datagridview我做不到抱歉我的英语我说得不够好,谢谢你的回答。最后我得到错误“并发冲突:更新命令影响了预期的 1 条记录中的 0 条”

最佳答案

您有更新查询吗?确保连同“选择”查询一起编写了“更新”

关于c# - Datagridview 更新到 DB mysql 错误 ""并发冲突 : the updatecommand affected 0 of the expected 1 records"",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24816204/

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