More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints Options · View
hong
Posted: Wednesday, February 16, 2011 6:56:00 PM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
This error "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints" can be caused by different reasons:
1. truly violating non-null, unique, or foreign-key constraints
2. a field length in the db doesn't match the one in the dataset. This can easily happen when you use Visual Studio designer.

Normally we would start looking at the first one. If we cannot find any problem, then we need to look at the second one - check all the MaxLength property of the columns in your DataTable. This can be an easy fix in many cases.

Alternatively you can set EnforceConstraints = False. However, it is not recommended because you will lose the guard for the table adapters.

If you are still tricked by this famous error message, then you need to find out exactly which field in the dataset schema is causing the problem by checking the errors on each row in a table in the typed dataset. It can be done quickly in a watch window in Visual Studio by adding a watch on <NameOfDataSetWithErrors>.<NameOfDataTableWithErrors>.GetErrors()

See this link for more details.
Sponsor
Posted: Wednesday, February 16, 2011 6:56:00 PM
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.053 seconds.