PC Review


Reply
Thread Tools Rate Thread

Catching for a System.Data.ConstraintException

 
 
=?Utf-8?B?QW5keQ==?=
Guest
Posts: n/a
 
      13th Jun 2006
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
 
Reply With Quote
 
 
 
 
Tom Porterfield
Guest
Posts: n/a
 
      13th Jun 2006
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.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/lib...dataerror.aspx,
including a little bit of sample code.
--
Tom Porterfield

 
Reply With Quote
 
=?Utf-8?B?QW5keQ==?=
Guest
Posts: n/a
 
      13th Jun 2006
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.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/lib...dataerror.aspx,
> including a little bit of sample code.
> --
> Tom Porterfield
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange System.Data.ConstraintException when executing GataGrid UpdateCommand in asp.net Kenneth Microsoft ADO .NET 0 3rd Nov 2004 04:10 PM
Re: keyref relationship in Typed Dataset causes System.Data.ConstraintException Frank Microsoft ADO .NET 0 3rd Jun 2004 10:21 AM
keyref relationship in Typed Dataset causes System.Data.ConstraintException =?Utf-8?B?bmltYQ==?= Microsoft C# .NET 0 2nd Jun 2004 12:06 AM
RE: keyref relationship in Typed Dataset causes System.Data.ConstraintException =?Utf-8?B?bmltYQ==?= Microsoft ADO .NET 2 1st Jun 2004 11:26 PM
System.Data.ConstraintException Failed to enable constraints. john_j_whalen@yahoo.com Microsoft ADO .NET 2 14th Dec 2003 03:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.