I run a Merge query against a SQL2008 db that returns the output from the merge using the following c# code:
cmd.CommandText = query;
if (conn.DBConn.State == ConnectionState.Closed) conn.DBConn.Open();
DbDataReader dbReader = cmd.ExecuteReader();
DataTable dt = new DataTable("Results");
dt.Load(dbReader);
The last line throws an error:
System.Data.ConstraintException - Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
I found this on MSDN, and it fits my scenario, but how do I actually fix this?
Clearing the primary key with dt.PrimaryKey=null;
does not work
The code above will be used for many tables.
violating non-null, unique, or foreign-key constraints.
non-null: check if some of the field(s) returning null and if null is allowed for the field.
unique: seems to be confirmed