Failed to enable constraints

C

cs_in_va

I get the following error when trying to access a page (prodcuts.aspx)
with a single drop down list box bound to a objectdata source linked
to my categoryBLL,.vb file. Here is what I have.

Table Categories with CategoryId and CategoryName.

My DAL for this is very simple again:

SELECT CategoryID, CategoryName, Image
FROM Categories

Have a categoryBLL with the following code:

Imports ADAHSTableAdapters

<System.ComponentModel.DataObject()> _
Public Class CategoriesBLL
Private _categoriesAdapter As CategoriesTableAdapter = Nothing
Protected ReadOnly Property Adapter() As CategoriesTableAdapter
Get
If _categoriesAdapter Is Nothing Then
_categoriesAdapter = New CategoriesTableAdapter()
End If

Return _categoriesAdapter (error line)
End Get
End Property


<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
True)> _
Public Function GetCategories() As ADAHS.CategoriesDataTable
Return Adapter.GetCategories()
End Function

<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
False)> _


Public Function GetCategoryByCategoryID(ByVal categoryID As
Integer) As ADAHS.CategoriesDataTable
Return Adapter.GetCategoriesByCategoryID(categoryID)
End Function
End Class


Error Message on aspx page:

Failed to enable constraints. One or more rows contain values
violating non-null, unique, or foreign-key constraints.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.ConstraintException: Failed to enable
constraints. One or more rows contain values violating non-null,
unique, or foreign-key constraints.

Source Error:


Line 2931: Me.Adapter.SelectCommand =
Me.CommandCollection(0)
Line 2932: Dim dataTable As ADAHS.CategoriesDataTable = New
ADAHS.CategoriesDataTable
Line 2933: Me.Adapter.Fill(dataTable)
Line 2934: Return dataTable
Line 2935: End Function


Stack Trace:


[ConstraintException: Failed to enable constraints. One or more rows
contain values violating non-null, unique, or foreign-key
constraints.]

.....More stuff,

CategoriesBLL.GetCategories() in C:\DNN_Web_Dev\ADAHS\App_Code\BLL
\CategoriesBLL.vb:18


Now when I preview the data in my tableadapter (categoriesDataTable) I
have no problem everything is displayed properly, but when I try and
link the Drop Down List to it I get the same error. I have tried not
using the BLL file and get the same error. Line 18 is "Return
_categoriesAdapter"

So where am I going wrong?

Thanks
 
M

Mr. Arnold

<snipped>

You have foreign key value that's in a table that's either a null value or
the value is not null but is pointing to key on a record in the foreign
table that's not there.
 
C

cs_in_va

<snipped>

You have foreign key value that's in a table that's either a null value or
the value is not null but is pointing to key on a record in the foreign
table that's not there.

Why would it work if I executed the query from the table adapter if
that were the case?

The table is fully populated. I have even taken away any FK's
responding to the categories table and still get the same issue.
 
M

Mr. Arnold

cs_in_va said:
Why would it work if I executed the query from the table adapter if
that were the case?

I don't know.
The table is fully populated. I have even taken away any FK's
responding to the categories table and still get the same issue.

I am just telling you what the message means. You got null data or invalid
data in a field pointing to a table that has a foreign constraint applied.

---------

Failed to enable constraints. One or more rows contain values
violating non-null, unique, or foreign-key constraints.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top