ASP.NET - ConstraintException was unhandled by user code
Been dabbling with a bit of ASP.NET. I current have the following error:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
It breaks on the following line:
开发者_如何学CDataTable propertyTable = pta.searchByType(sType);
Code:
String sType = Request.QueryString["type"];
DataSetTableAdapters.propertiesTableAdapter pta = new DataSetTableAdapters.propertiesTableAdapter();
DataTable propertyTable = pta.searchByType(sType);
if (propertyTable.Rows.Count > 0)
{
lblStatus.Text = "Your Results";
gvProperty.DataSource = propertyTable;
gvProperty.DataBind();
}
The query that pta.searchByType(sType);
is calling is:
SELECT property_id, name, description, price, image, town
FROM properties
WHERE (date_approved IS NOT NULL) AND (property_type = @property_type)
The primary key for the properties table is property_id
, the table has one FK that links to a users table but that's it.
Any help pointing me in the right direction is great. If you need any more details just drop them in the comments below.
Thanks :)
Are you selecting ALL the columns?
See: http://forums.asp.net/t/1400495.aspx/1
You can always cheat and set enable constraints to false on the table adapter, too.
精彩评论