0

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
Codes with Hammer
  • 788
  • 3
  • 16
  • 47

1 Answers1

1

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.

Codes with Hammer
  • 788
  • 3
  • 16
  • 47
  • could you please share a code how you made this work. – JSB Sep 11 '22 at 02:48
  • @JSB: It's been nine years, I no longer have access to the code. I _think_ the constructor for the table adapter used a particular query, which was what needed changing. – Codes with Hammer Sep 12 '22 at 14:12