Reputation: 442
dsrm_usersTableAdapters.rm_usersIPTableAdapter _tuser = new dsrm_usersTableAdapters.rm_usersIPTableAdapter();
dsrm_users _dsuser = new dsrm_users();
_dsuser.EnforceConstraints = false;
dsrm_users.rm_usersIPDataTable _muser = _dsuser.rm_usersIP;
_tuser.FillBy(_muser, _IP);
it is very good works;
However, when I use ObjectDataSource and connect to grid view using GetData() method, it gives an error;
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints Error;
I go to the Dataset and I set EnforceConstraints=false in Property Window , and I try agin its give again same erorr. So EnforceConstraints=false does not work with GetDATA();
So what can I do now? How can I use ObjectDataSource using GetData() without this error.
Upvotes: 2
Views: 4131
Reputation: 25197
I would first try and determine why your constraints are failing.
You can determine this by
_dsuser.EnforceConstraints = false;
//fill info
try
{
_dsuser.EnforceConstraints = true;
}
catch
{
if (ds.HasErrors)
{
DataRow[] drs = _dsuser.[datatablename].GetErrors();
foreach(DataRow dr in drs)
{
foreach(DataColumn dc in dr.GetColumnsInError())
{
Console.Write(dr.GetColumnError(dc));
}
}
}
}
This will print to the console any errors in the datatable
You can also loop thru' the tables with ds.tables if you do not know the table name.
Upvotes: 1