X
    Categories: General

ConstraintException occurred when updating DataTable with TableAdapter

I have been using SqlDataAdapter and strong typed DataSet and DataTable in my projects in .NET 1.1 for quite some time and have not had any problems. Now, in .NET 2.0, SqlDataAdapter is replaced with TableAdapter, which is much easier than SqlDataAdapter to create a data access layer. When I played with it in one of my projects last week, I came across an exception error when updating a DataTable with TableAdapter. The error happens when inserting new records in a database table that has an AutoIncrement primary key and says something like:

“ConstraintException was unhandled. Column ‘EmailMessageId’ is constrained to be unique. Value ‘1’ is already present.”

Thanks to David Hayden’s post regarding this error on his blog, I could quickly fix the error by following his instructions. But what surprised me is that David blogged this error in July 2006, and I believe there are many developer out there having the same error, yet this bug has not been fixed in Visual Studio 2005 SP1.

Jeffrey:
Related Post