求教清空DataGridView及数据库表相关数据的问题

bulls5988 bulls5988 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面代码是清除按钮,之前已经在查找事件中把SQL查询结果放进DataGridView里了。
现在全部删除(清除)后会提示这一句: this.d_report.Rows.RemoveAt(0);错误“无法删除未提交的新行”
但是其实数据已经被删除了,虽然可以用try catch屏蔽这个错误。不过解决根本问题。求教大家这个错误为什么出现,怎么解决呢?


DialogResult clear_up = MessageBox.Show("您真的要清除所有记录吗?",
"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch (clear_up)
{
case DialogResult.Yes:
SqlCommandBuilder delete = new SqlCommandBuilder(find_do);
for (int i = d_report.Rows.Count; i > 0; i--)
{
this.d_report.Rows.RemoveAt(0);
find_do.Update(ds, "rs");
}
MessageBox.Show("号码已经全部删除!", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
break;
case DialogResult.No:
break;
}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
bulls5988
C# 111,130 成员 642,540 内容