tags:

views:

307

answers:

2

Hi;

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.

A: 

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

Nathan Koop
A: 

Every time I get this in an ObjectDataSource for a report it is a serious fight.

My latest go-around ended when I deleted the primary key from the datatable in my XSD file. I never set a primary key, but apparently the designer decided to set one (which was not unique in the data).

Very annoying and certainly something Microsoft should address either in the exception messages or with an easier way to debug an objectdatasource.

Bill Kuhn