473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Catching for a System.Data.ConstraintException

I have a C# application that is using a DataGridView (DGV). The DGV uses a
table adapter to connect to the datasource, which uses a DataSet as the data.
The DataSet has some constraints placed on them (PK on two columns).

When I add / update a column that violates the PK constraint, I get an error
stating the following:

System.Data.ConstraintException: Column 'Item, BItem' is constrained to be
unique. at System.Data.UniqueConstraint.CheckConstraint...... ..at
System.Windows.Forms.DataGridView.DataGridViewData Connection.OnRowValidating.
To Replace this default dialog please handle the DataError event.

I cannot for the life of me find how to replace that "default dialog" or how
to trap for this error message. I know it must be in the DataSet
configuration, but not sure where to place a try.....catch. Google didn't
provide any results that helped correct this.

Would anyone be able to help me replace this default dialog?

Thanks
Andy
Jun 13 '06 #1
2 11561
Andy wrote:
I have a C# application that is using a DataGridView (DGV). The DGV uses
a table adapter to connect to the datasource, which uses a DataSet as the
data. The DataSet has some constraints placed on them (PK on two columns).

When I add / update a column that violates the PK constraint, I get an
error stating the following:

System.Data.ConstraintException: Column 'Item, BItem' is constrained to be
unique. at System.Data.UniqueConstraint.CheckConstraint...... ..at
System.Windows.Forms.DataGridView.DataGridViewData Connection.OnRowValidating.
To Replace this default dialog please handle the DataError event.

I cannot for the life of me find how to replace that "default dialog" or
how to trap for this error message. I know it must be in the DataSet
configuration, but not sure where to place a try.....catch. Google didn't
provide any results that helped correct this.


You're looking in the wrong place. The DataError event is raised by your
instance of DataGridView. More info on this event can be found at
http://msdn2.microsoft.com/en-us/lib...dataerror.aspx,
including a little bit of sample code.
--
Tom Porterfield

Jun 13 '06 #2
Mr. Porterfield:

Thank you very much. That is what I was missing. I assumed it was coming
from my dataset, and not the DataGridView. I have found the method and now
trapping for it.
"Tom Porterfield" wrote:
Andy wrote:
I have a C# application that is using a DataGridView (DGV). The DGV uses
a table adapter to connect to the datasource, which uses a DataSet as the
data. The DataSet has some constraints placed on them (PK on two columns).

When I add / update a column that violates the PK constraint, I get an
error stating the following:

System.Data.ConstraintException: Column 'Item, BItem' is constrained to be
unique. at System.Data.UniqueConstraint.CheckConstraint...... ..at
System.Windows.Forms.DataGridView.DataGridViewData Connection.OnRowValidating.
To Replace this default dialog please handle the DataError event.

I cannot for the life of me find how to replace that "default dialog" or
how to trap for this error message. I know it must be in the DataSet
configuration, but not sure where to place a try.....catch. Google didn't
provide any results that helped correct this.


You're looking in the wrong place. The DataError event is raised by your
instance of DataGridView. More info on this event can be found at
http://msdn2.microsoft.com/en-us/lib...dataerror.aspx,
including a little bit of sample code.
--
Tom Porterfield

Jun 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: nima | last post by:
Hi I have two tables in my database. PRODUCT and PRODUCT_GROUP. PRODUCT has a foreign key to PRODUCT_GROUP. I generated a typed dataset using VS.net and added a relationship between the two...
0
by: Nathan Baulch | last post by:
If I call EndCurrentEdit on a data linked form which contains data that breaks a unique constraint, a ConstraintException is thrown as expected. If I catch that exception and call EndCurrentEdit...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
1
by: H. Neal | last post by:
I'm getting a error message in my program that states there is ConstraintException Error, because a row had "violated" the "rules" of the MS Access Database... is there any way to get rid of this...
5
by: cazconv2007 | last post by:
hi i need to catch and try exceptions , one for int and one for an array out of bounds i dont undertand how my code is'nt working for array out of bounds heres my code import java.util.* ; ...
1
by: Paul | last post by:
Hi, I need know the fields involved in a ConstraintException with code. Any idea? Thanks
0
by: Paul | last post by:
Hi, I need know the fields involved in a ConstraintException with code. Any idea? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.