Tyred of the "Failed to enable constraints. One
or more rows contain values violating non-null, unique, or foreign-key
constraints". " error when filling dataset?
Well, the detailed error info is buried inside the dataset (not deeply buried after all...)
But for the lazy people (like me), you can add this class to whatever project you want and just call the static method in the inmediate window, passing the dataset, to see from where the error comes from...
Example: DataSetDebugger.GetErrors(myDataset)
The class:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;
namespace DataDebug
{
class DataSetDebugger
{
public static void GetErrors(DataSet ds)
{
Debug.WriteLine("--- Checking errors on dataset: '" + ds.DataSetName + "'---");
foreach (DataTable tb in ds.Tables)
{
if (tb.HasErrors)
{
Debug.WriteLine(" Errors found on table: '" + tb.TableName + "'");
int i = 0;
foreach (DataRow dr in tb.GetErrors())
{
Debug.WriteLine(" Errors found on row: [" + i.ToString() + "]:");
Debug.WriteLine(" - Error description: " + dr.RowError);
foreach(DataColumn col in dr.GetColumnsInError())
{
Debug.WriteLine(" - Column: " + col.ColumnName + " Error: " + dr.GetColumnError(col));
}
i++;
}
}
}
Debug.WriteLine("--- Checking done ---");
Debug.WriteLine("");
}
}
}
Subscribe to:
Post Comments (Atom)
2 comments:
Does your website have a contact page? I'm having a tough time locating it but, I'd like to
send you an email. I've got some ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.
Here is my webpage: instant loans online
I savour, lead to I discovered exactly what I used to be looking for.
You've ended my four day long hunt! God Bless you man. Have a nice day. Bye
my website: I can't
believe this
Post a Comment