I've done this numerous times
Big picture:
CRUD WinForms application with SQL Server 2008 R2 database.
I 've added few new things and one which I haven't meddled with is now broken.
Code is standard, nothing exotic here and it worked before last changes.
try{
trans = _connection.BeginTransaction();
_workingOrdersAdapter.Transaction = trans;
_rawMaterialsStockAdapter.Transaction = trans;
_stockEntriesAdapter.Transaction = trans;
_stockEntriesItemsAdapter.Transaction = trans;
_stockReservationAdapter.Transaction = trans;
_mixingPlanUtemsAdapter.Transaction = trans;
retval = _workingOrdersAdapter.Update(dataSet.WorkingOrders);
retval += _mixingPlanUtemsAdapter.Update(dataSet.MixingPlanItems.Select("","", DataViewRowState.Deleted));
retval += _mixingPlanUtemsAdapter.Update(dataSet.MixingPlanItems.Select("","", DataViewRowState.ModifiedCurrent));
retval += _rawMaterialsStockAdapter.Update(dataSet.RawMaterialsStock);
retval += _stockEntriesAdapter.Update(dataSet.StockEntries);
retval += _stockEntriesItemsAdapter.Update(dataSet.StockEntryItems);
retval += _mixingPlanUtemsAdapter.Update(dataSet.MixingPlanItems.Select("", "", DataViewRowState.Added));
retval += _stockReservationAdapter.Update(dataSet.StockReservations);
trans.Commit();
}catch(SqlException sqlex)
{
}
When updating data from dataset to DB on one data adapter INSERT fails:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_MixingPlanItems_WorkingOrders". The conflict occurred in database "Recepture", table "dbo.WorkingOrders", column 'WorkingOrderID'.
The statement has been terminated.
WTH?!?
When I execute query in Management Studio it works perfectly.
It is a simple INSERT query.
When updating data (with UPDATE query) it runs as it should.
So far I have done the following:
Configured data adapter several times.
Removed and added particular adapter again.
Removed and added particular table connection in DB.
Please excuse me if I am being incomprehensible I have't slept much. :(