INSERT语句与FOREIGN KEY约束冲突" FK_Orders_Employees"

时间:2016-10-17 23:22:51

标签: vb.net constraints foreign-key-relationship northwind

我在构建名为OnlineOrdering的Web应用程序的示例中使用了在线订购应用程序。在Mastering Visual Basic 2010第20章中找到它。在我进入Check Out,orderAdapter.Update(orders)的Cart.aspx Web表单步骤之前,每件事情都有效。如果有人使用它,我会很感激。



Protected Sub bttnCheckOut_Click(ByVal sender As Object,
                                     ByVal e As EventArgs) Handles bttnCheckOut.Click
        Dim productsAdapter As New NorthwindTableAdapters.ProductsTableAdapter
        Dim products As Northwind.ProductsDataTable = productsAdapter.GetData

        Dim ordersAdapter As New NorthwindTableAdapters.OrdersTableAdapter
        Dim orders = ordersAdapter.GetData

        Dim orderDetailsAdapter As New NorthwindTableAdapters.Order_DetailsTableAdapter
        Dim orderDetails = orderDetailsAdapter.GetData

        Dim order = orders.AddOrdersRow(Session("userId"), CInt(Session("employeeId")),
                                        Date.Now.Date, Date.Now.AddDays(7).Date,
                                        Date.MinValue, 1,
                                        Nothing, Nothing, Nothing, Nothing,
                                        Nothing, Nothing, Nothing)
        order.SetShippedDateNull()
        ordersAdapter.Update(orders)
        orders.AcceptChanges()
        For Each orderDetail In queryResult
            Dim product = products.FindByProductID(orderDetail.ProductID)
            orderDetails.AddOrder_DetailsRow(order, product, orderDetail.UnitPrice,
                                             orderDetail.Quantity, orderDetail.Discount)
        Next
        orderDetailsAdapter.Update(orderDetails)
        orderDetails.AcceptChanges()
        Response.Redirect("Confirmation.aspx")

    End Sub




它在代码行ordersAdapter.Update(orders)中断并收到此消息:INSERT语句与FOREIGN KEY约束冲突" FK_Orders_Employees"。冲突发生在数据库中 " Northwind",table" dbo.Employees",column' EmployeeID'。 该语句已终止。

0 个答案:

没有答案