Hello,
I have a database with 3 tables: Customer, Order, Orderdetails.
The tables a related to each other with:
Customer.customerID, Order.customerID, Orderdetails.OrderID
With a selectquery I filled a dataset with data from these tables.
De data is now in a new dataset-table "NewOrders".
What I now wanna do is add a new row to the database-table Orderdetails.
The new row must have the same values as in the dataset-table "NewOrders" except it must get a new value for the OrderDate-column. The date is selected with a datetimepicker.
I have for example the following code:
But i get the following error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Orders_Customer". The conflict occurred in database "OrderData", table "dbo.Customer", column 'CustomerID'.
What do I have te change?
Trying for days now!!
I have a database with 3 tables: Customer, Order, Orderdetails.
The tables a related to each other with:
Customer.customerID, Order.customerID, Orderdetails.OrderID
With a selectquery I filled a dataset with data from these tables.
De data is now in a new dataset-table "NewOrders".
What I now wanna do is add a new row to the database-table Orderdetails.
The new row must have the same values as in the dataset-table "NewOrders" except it must get a new value for the OrderDate-column. The date is selected with a datetimepicker.
I have for example the following code:
VB.NET:
'Fill the DataSet using the SqlDataAdapter
objdataAdapter.Fill(objDataSetOrders, "NewOrders")
'Add new Rows
Dim objdatarow As DataRow
objdatarow = objDataSetOrders.Tables("NewOrders").NewRow
objdatarow("CustomerID") = objDataSetOrders.Tables("NewOrders").Rows(0).Item("CustomerID")
objdatarow("CustomerName") = objDataSetOrders.Tables("NewOrders").Rows(0).Item("CustomerName")
objdatarow("OrderID") = objDataSetOrders.Tables("NewOrders").Rows(0).Item("OrderID")
objdatarow("OrderName") = objDataSetOrders.Tables("NewOrders").Rows(0).Item("OrderName")
objdatarow("OrderDate") = DateTimePicker1.value.Date.ToShortDateString
'add datarow
objDataSetOrders.Tables("NewOrders").Rows.Add(objdatarow)
'update dataset-table
objdataAdapter.Update(objDataSetOrders.Tables("NewOrders"))
But i get the following error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Orders_Customer". The conflict occurred in database "OrderData", table "dbo.Customer", column 'CustomerID'.
What do I have te change?
Trying for days now!!