在行上输入DataGridView System.Data.ConstraintException [英] DataGridView System.Data.ConstraintException on row enter

查看:48
本文介绍了在行上输入DataGridView System.Data.ConstraintException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅作为开始说明:我正在研究一个现有应用程序,该应用程序已传递给我们,并试图解决并修复错误.

Just as a starting note: I'm going through an existing app which was passed down to us and trying to go through and fix the bugs.

我一直在遇到一个特定的DataGridView错误的问题.给我一个唯一的ID约束异常.奇怪的是,当我将新项目添加到表中时,我没有收到此错误;当我尝试在表格中选择一行(任何行,它不一定是新添加的项目)时,都会收到此错误.DataGridView.当您向该表中添加项目时,它会顺序地增加ID,并且从调试中看去,ID似乎正确地增加了,因此我不确定为什么会收到此错误.我是Visual Studio的新手,所以我对为什么选择行而不是将项目添加到表时收到此错误感到非常困惑.

I've been having issues with one particular DataGridView erroring out; giving me a Unique Constraint Exception on the ID. The strange thing is that I don't receive this error when I add the new item to the table, I receive it when I try to select a row (any row, it doesn't have to be the newly added item) in the DataGridView. When you add an item to this table it increments the ID sequentially and from debugging it seems like the ID's are incrementing correctly so I'm not sure why I am receiving this error. I'm new to Visual Studio so, I'm really confused as to why I'm receiving this error when I select a row as opposed to when the item is added to the table.

反正我有话要说这个错误发生在哪一行,或者为什么我在DGV中选择一行时为什么会发生呢?我尝试在异常"窗口中标记System.Data.ConstraintException,因为它通常可以正常工作,但是该程序不会像其他异常一样停止并带我进入代码中的相应行.关闭对话框后,对话框将立即弹出.

Is there anyway for me to tell what line this error is occurring on or why it is happening when I select a row in the DGV? I tried marking the System.Data.ConstraintException in the Exceptions window as this usually works, but the program doesn't halt and take me to the corresponding line in the code as it usually does with other exceptions. The dialog window just pops up and the program continues as normal once I close it.

我还要注意的另一件事是,已使用正确的ID和所有内容将项目正确添加到数据库中.除了弹出异常对话框外,这似乎没有引起任何问题.我知道我可以处理DataError事件以停止显示对话框,但是我真的很想解决这个问题,而不是仅仅掩盖它.

Another thing that I should note is that the item is added to the database properly, with the correct ID and everything. It doesn't seem to be causing an issue besides having the exception dialog popping up. I know I can just handle the DataError event to stop the dialog from showing, but I'd really like to solve this instead of just covering it up.

可以在此处查看例外的屏幕截图:

A screenshot of the Exception can be seen here:

http://i.imgur.com/VICFv.png

同样,为了清楚起见,添加新记录后在DataGridView中选择ANY行时会弹出此异常.另外,我没有将任何事件设置为发生在onRowEnter上.

And again, just to be clear, this exception pops up when I select ANY row in the DataGridView after the adding of a new record. Also I do not have any event set to occur onRowEnter.

任何人都非常感谢!预先感谢.

Any helps greatly appreciated! Thanks in advance.

推荐答案

在您的ID序列中可能存在某种热点",所以即使在选择该行之后如果ID正确递增,则可以使用已经存在的ID翻倍.

May be you have kind of "hot spots" in your ID sequence, so even if after selection of the row if the ID is correctly incremented it can doubled with already present one.

这篇关于在行上输入DataGridView System.Data.ConstraintException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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