I cannot set any constraints in my datatable if i merge two datatables dt1.Merge(dt2);
It shows error like this Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
By default i view in visualizer it shows constraints count as 2. How to remove constraints from datatable and solve this error?
To remove constraints from a DataTable you can use the Clear method of the Constrains property:
myDataTable.Constraints.Clear();
try iterating the constraints of datatable and remove them using
private void RemoveConstraint(DataTable table,
Constraint constraint)
{
if(table.Constraints.Contains(constraint.ConstraintName))
if(table.Constraints.CanRemove(constraint))
table.Constraints.Remove(constraint);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With