userDs1.EnforceConstraints problem

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,772
Messages
2,569,588
Members
45,100
Latest member
MelodeeFaj
Top