Catching for a System.Data.ConstraintException

G

Guest

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.DataGridViewDataConnection.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
 
T

Tom Porterfield

Andy said:
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.DataGridViewDataConnection.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/library/system.windows.forms.datagridview.dataerror.aspx,
including a little bit of sample code.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top