Failed to enable constraints when filling datatable


I am loading a data table from an XSD data set in C# in MSVS 2012. The standard GetData() method runs properly. However, my custom query GetDataCustom(), which returns only a few fields from the data set, throws the popular exception:


Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.


I used the Detailed Constraint Exception posted in reply to a similar issue here on SOV, which showed this detail:

Error filling table No Row Errors reported in DataTable=[datatable_Custom]

I set EnforceConstraints = false on my data set, but the exceptions still were thrown. I have looked through the many questions on SOV on this issue, but none of the other fixes helped. What else can I try?

Edited to add code block:

ds_Sample dsSample = new ds_Sample(); dsSample.Clear(); dsSample.EnforceConstraints = false; ds_SampleTableAdapters.ta_Sample taCustom = new ds_SampleTableAdapters.ta_Custom(); ds_Sample.dt_CustomDataTable dtCustom = taCustom.GetDataCustom();//throws exception


Fixed it myself: The table adapter had all the fields in the data set, but my query only had some of the fields in the table adapter. I changed the table adapter to use the query of interest, and the problem was resolved.

Therefore, the constraint violation was most likely null data in NOT NULL fields.


  • Overridable Methods In Constructors -Help to Fix
  • Can I allow indexing (by search engines) of restricted content without making it public?
  • How can I find a style trigger-embedded element by name in WPF?
  • Insert null in a database
  • SVG Fill Width to Child Elements
  • Slowly changing dimension - What is Pure type 6 implementation
  • SQL append distinct values from two columns and two tables
  • Hibernate: Inheritance and relationship mapping + generics
  • Doctrine2 inverse persistance not working in nested forms
  • Implementation of RTTI using typeid
  • Should I use composite primary keys in Grails?
  • Many to Many in Linq using Dapper
  • Extending the Django 1.11 User Model
  • How to Model Ternary Relationship in CakePhp?
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • Azure table store snapshot/backup capability
  • How to disable all widgets inside Panel or inside Composite?
  • Security issues with PHP's Readfile method
  • Problems installing Yesod for Haskell
  • Unable to install Git-core+svn by MacPorts
  • Why querying a date BC is changed to AD in Java?
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • Chrome doesn't support silverlight anymore? How to solve this?
  • ilmerge with a PFX file
  • Why value captured by reference in lambda is broken? [duplicate]
  • vba code to select only visible cells in specific column except heading
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • Convert array of 8 bytes to signed long in C++
  • Do I've to free mysql result after storing it?
  • Transpose CSV data with awk (pivot transformation)
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Understanding cpu registers
  • Why joiner is not used after Sequence generator or Update statergy
  • LevelDB C iterator
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • Sorting a 2D array using the second column C++
  • How can i traverse a binary tree from right to left in java?
  • UserPrincipal.Current returns apppool on IIS