An unhandled exception of type 'System.Data.ConstraintException' occurred in system.data.dll
Additional information: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
The code works fine with small tables even when the small tables have nulls and no keys. The code always fails on large tables even when there are no nulls and unique keys. Does anyone have any clues? Is there a limit to the size of tables you can load into a MySqlDataTable (and MySQLDataSet)?
Code: Select all
static void MySQLDirect()
{
string strConnect, strQuery;
strConnect = "Host=EvoW4000; User=pjc; Password=timaru; Database=BCResearch";
strQuery = "Select * from _dd_fields";
MySqlConnection db = new MySqlConnection(strConnect);
db.Open();
MySqlCommand dbCommand = new MySqlCommand(strQuery, db);
string val;
try
{
int rowID = 0;
MySqlDataTable dt = new MySqlDataTable(dbCommand);
dt.Constraints.Clear();
dt.Active = true;
foreach (DataRow currRow in dt.Rows)
{
Console.WriteLine("Record Start {0}", rowID++);
int colID = 0;
foreach (DataColumn currCol in dt.Columns)
{
val = currRow[currCol].ToString();
Console.WriteLine("{0} \t {1}", colID++, val);
}
Console.WriteLine("Record End");
}
dt.Dispose();
}
finally
{
db.Close();
}
}
}