By default, MS Visual Studio debugging message does not show useful details if e.g. the Fill() method of a DataSet/DataTable causes a ConstraintException . Especially if your table has a lot of columns, indexes, foreign keys etc., finding the cause can take a long time.
But if you catch the Exception and use its GetErrors() method, you will get more information in detail.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
try { this.yourTableAdapter.FillById(this.yourtable, id); } catch (ConstraintException) { DataRow[] rowErrors = db.yourtable.GetErrors(); System.Diagnostics.Debug.WriteLine("Errors:" + rowErrors.Length); for (int i = 0; i < rowErrors.Length; i++) { System.Diagnostics.Debug.WriteLine(rowErrors[i].RowError); foreach (DataColumn col in rowErrors[i].GetColumnsInError()) { System.Diagnostics.Debug.WriteLine(col.ColumnName + ":" + rowErrors[i].GetColumnError(col)); } } } |
Comments