在名为 OnlineOrdering 的构建 Web 应用程序的示例中,我一直在使用在线订购应用程序。在 Mastering Visual Basic 2010 书第 20 章中找到它。在我到达 Check Out 的 Cart.aspx Web 表单步骤之前,一切正常,ordersAdapter.Update(orders)。如果有人使用它,我将不胜感激。
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”、表“dbo.Employees”、列“EmployeeID”中。该语句已终止。