I am putting together an editor for an application I am creating.

The data ultimately resides on a SQL server.

The application loads some of the data from the server into a dataset, which is used by a bindingsource which is then used by a bindingnavigator. (wow that's a mouthful).

The issue is, the dataset contains some constraints, one of them involves a "code" that must be unique, similar to an account number for any company, they can't repeat but are more useful to end users than the identity data.

Anyway, if I have 2 records, and the code for one record is A and is B for the other...if I change B to A, I get a constraint exception. Great! That's what's supposed to happen, except that there are other text box controls on the form that are bound too dataset fields that have a unique constraint...is there any way at all of finding out what form control contains the invalid data?

Also, to throw another wrench in the gears, the form contains 2 total bindingsources, both of which are bound to tables that have unique constraints.

I have looked everywhere I can think of and I can't find anything on handling these errors correctly other than a message box that just shows the standard e.Message error (which is useless if you ask me).


7 Years
Discussion Span
Last Post by zachattack05

Have you looked at the inner exception? Not sure if this will help, but it's the first place I'd look.

Me too...it's null :(

The exception occurs when EndEdit() is called on the bindingSource with the error. I just can't figure this out...The exception message says: "Column 'ParentCode' is constrained to be unique. Value 'ATI2' is already present." so the information I am looking for can be found, it has to be there...I just can't find it!

Here's the exception details from the debugger, do you see anything that I might be missing?

System.Data.ConstraintException was caught
Message=Column 'ParentCode' is constrained to be unique. Value 'ATI2' is already present.
at System.Data.UniqueConstraint.CheckConstraint(DataRow row, DataRowAction action)
at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataRow.EndEdit()
at System.Data.DataRowView.EndEdit()
at System.Windows.Forms.CurrencyManager.EndCurrentEdit()
at System.Windows.Forms.BindingSource.EndEdit()
at DATA.Editors.Companies.toolStripButton1_Click(Object sender, EventArgs e) in U:\Projects\DATA\DATA\Editors\Companies.cs:line 38

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.