更新期间C#DBConcurrencyException [英] C# DBConcurrencyException during update

查看:90
本文介绍了更新期间C#DBConcurrencyException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找好几天并尝试了很多很多解决方案而没有成功。

我可以查看,创建和删除没有问题的行但由于某种原因我在更新行时遇到问题。

任何帮助都会非常感激。



I have been searching for days and have attempted many, many solution without success.
I can view, create and delete rows with no problems but for some reason I am having a problem updating rows.
Any help would be great appreciated.

private void cmdApproved_Click(object sender, EventArgs e)
  {
      foreach (DataGridViewRow dgr in dataGridView1.SelectedRows)
      {
          DataRow dr = workflowDataSet.tblAbm.Rows.Find(dgr.Cells[9].Value);
          if (dr != null)
          {
              dr["abmStatus"] = 5;
              dr["releasedDate"] = DateTime.Now;
               tblAbmTableAdapter.Update(workflowDataSet.tblAbm);
          }
      }
      this.tblAbmTableAdapter.GetApprovalList(this.workflowDataSet.tblAbm, Globals.gUserId);
  }

推荐答案

来自msdn

From msdn
The exception that is thrown by the DataAdapter during an insert, update, or delete operation if the number of rows affected equals zero.



因此,您需要查看什么是UPDATE语句适配器。它很可能包含一个WHERE子句,您可以在其中找到导致在执行期间更新零行的条件。在没有看到UPDATE语句的情况下,我们只能推测WHERE子句中使用的列中的某些值已被更改。


So you need to see what is the UPDATE statement for the adapter. It most likely contains a WHERE clause where you'll find a condition that causes zero rows to be updated during the execution. Without seeing the UPDATE statement we can only speculate that some values in the columns used in the WHERE clause have been changed.


Mika,

你是对的。我设置了一个自定义更新,它就像一个魅力。我感到有点傻,这很简单,但感谢你指点我正确的方向。
Mika,
You were correct. I set a custom update and it worked like a charm. I feel a little silly that it was that simple but appreciate you pointing me in the right direction.


这篇关于更新期间C#DBConcurrencyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆