Bound form - getting error "Failed to enable constraints"

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

Hi all

I'm hoping someone can help with a problem. I'm using VB2005, and
trying to learn by creating a data-driven application using Northwind
on SQL 2005.

I'm trying to build a form which shows basic customer and order
information, with the order information in a DataGridView. So far, so
good. But when the user double-clicks on an item in the DataGridView,
I want a second form to open showing details of this order.

I've got a Dataset called NorthwindDataSet, which I created by using
Data --> Add new data source, based on the Customers, Orders, Order
Details and Products tables.

I then added a new TableAdapter, based on the following Select
statement:

SELECT Customers.CompanyName, Customers.ContactName,
Customers.City, Customers.Country, Orders.OrderID, Orders.OrderDate,
[Order Details].Quantity,
[Order Details].UnitPrice,
Products.ProductName
FROM Customers INNER JOIN
Orders ON Customers.CustomerID =
Orders.CustomerID INNER JOIN
[Order Details] ON Orders.OrderID = [Order
Details].OrderID INNER JOIN
Products ON [Order Details].ProductID =
Products.ProductID


I added a new query with methods FillByOrderID and GetDataByOrderID,
which is exactly as above, plus the clause:
WHERE Orders.OrderID= @OrderID

Using this as the source, I then created a bound form, and amended the
code in the Load event of the form to read:

Me.FullDetailsTableTableAdapter.FillByOrderID
(Me.NorthwindDataSet.FullDetailsTable, 10248)

where I've used 10248 as a sample order id, just to check that it
works.

When I open this form from the main form, I get the exception:

"Failed to enable constraints. One or more rows contain values
violating non-null, unique, or foreign-key constraints."

I don't understand why I would be getting this error, based on my
column selections, and on the fact that I'm not (at least not
intentionally) trying to update data at this stage.

I can "bypass" the error, based on a suggestion by the Exception
Assistant, by adding the following line prior to calling the
FillByOrderID method:

NorthwindDataSet.EnforceConstraints = False

However, firstly it seems like a REALLY bad idea to be turning off
database constraints (even if only in the dataset, rather than on the
DB itself), and secondly, I cannot turn the constraints back on again
after this line has executed - I get the same error.

Can anyone shed any light?

Many thanks

Andrew Richards
 
Back
Top