开发者

DataGridView System.Data.ConstraintException on row enter

开发者 https://www.devze.com 2023-03-17 06:17 出处:网络
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.

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.

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.

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.

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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消