B
Britney
hi guys,
I tried to return data from datagrid.
but I got some errors.
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Line 61:
Line 62:
Line 63: sqlDataAdapter1.Fill(userDs1);
Line 64: DataGrid1.DataBind();
Line 65:
but if I put the following code, the errors goes away.
userDs1.EnforceConstraints = false;
So what is the problem???
// HERE IS MY CODE in codebehind.
GetUsersQuery.Append("SELECT user_id, nick_name, sex, age, country, state, has_picture, self_description FROM users WHERE 1=1 ");
if (Sex.SelectedItem.Value != null)
{
GetUsersQuery.Append(" AND sex=@sex ");
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sex", System.Data.SqlDbType.VarChar, 10, "sex"));
this.sqlSelectCommand1.Parameters["@sex"].Value = Sex.SelectedItem.Value;
}
this.sqlSelectCommand1.CommandText = GetUsersQuery.ToString();
//DISABLE THIS LINE TO to get rid of error.
//userDs1.EnforceConstraints = false;
sqlDataAdapter1.Fill(userDs1);
DataGrid1.DataBind();
I tried to return data from datagrid.
but I got some errors.
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Line 61:
Line 62:
Line 63: sqlDataAdapter1.Fill(userDs1);
Line 64: DataGrid1.DataBind();
Line 65:
but if I put the following code, the errors goes away.
userDs1.EnforceConstraints = false;
So what is the problem???
// HERE IS MY CODE in codebehind.
GetUsersQuery.Append("SELECT user_id, nick_name, sex, age, country, state, has_picture, self_description FROM users WHERE 1=1 ");
if (Sex.SelectedItem.Value != null)
{
GetUsersQuery.Append(" AND sex=@sex ");
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sex", System.Data.SqlDbType.VarChar, 10, "sex"));
this.sqlSelectCommand1.Parameters["@sex"].Value = Sex.SelectedItem.Value;
}
this.sqlSelectCommand1.CommandText = GetUsersQuery.ToString();
//DISABLE THIS LINE TO to get rid of error.
//userDs1.EnforceConstraints = false;
sqlDataAdapter1.Fill(userDs1);
DataGrid1.DataBind();