You've been very helpful, can you just go away now.
Sometimes when dealing with a typed dataset (a good idea) you have a problem with constraints, or with nullable fields, or with other stuff. Microsoft gives you a less-than-helpful exception that says "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
Right...
Well, if you use:
It just makes you feel all warm and fuzzy inside, doesn't it?
Right...
Well, if you use:
then you can call this method which will output the table, row, column, and exact constraint that was violated.ds.EnforceConstraints = false;
public void GetDataSetErrors(DataSet ds){try { ds.EnforceConstraints = true; }
catch(Exception ex) {
foreach
(DataTable table in ds.Tables) {foreach (DataRow row in table.GetErrors()){ System.Diagnostics.Trace.WriteLine("Table: "+
table.TableName); System.Diagnostics.Trace.WriteLine(ex.Message
); System.Diagnostics.Trace.WriteLine("Row: "
+row.RowError); foreach (DataColumn col in
row.GetColumnsInError())
{ System.Diagnostics.Trace.WriteLine("Column
" +
col.ColumnName); System.Diagnostics.Trace.WriteLine(
row.GetColumnError(col)); } } } } }
It just makes you feel all warm and fuzzy inside, doesn't it?
Comments