//Define two strongly-typed DataSets
using Acme.StrongTypesNS; dsOrderDataSet dsOrders; dsOrderDataSet dsUpdatedRecs; . . . // Populate the dsUpdatedRecs DataSet with only the changed rows dsUpdatedRecs = (dsOrderDataSet) (dsOrders.GetChanges( )); // Confirm that there are updates before continuing if (dsUpdatedRecs != null) { appObj.UpdateDS(ref dsUpdatedRecs); if (dsUpdateRecs.Tables["orderline"].HasErrors) { displayMessage = "The following Orderline rows were not updated:"; foreach(DataRow failedRow in dsUpdatedRecs.Tables ["orderline"].Rows) { if (failedRow.HasErrors) { displayMessage += "\n\r Line number: " + failedRow["linenum"].ToString( ) + ", Error Message: " + failedRow.RowError; } . . . } } } else { dspMsg ="All updates succeeded"; dspCaption = "Save completed"; dspButton = MessageBoxButtons.OK; resultDlog = MessageBox.Show(this, dspMsg, dspCaption, dspButton, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); } // Remove the pending additional order lines before merging to prevent // duplicate rows if the key fields on the row number were changed during the // update. foreach(DataRow curRow in dtTableTwo.Select("", "", DataViewRowState.Added)) { dtTableTwo.Rows.Remove(curRow); } // Merge the changes dsOrders.Merge(dsUpdatedRecs); // Reset the row state for the modified rows now that changes dsOrders.AcceptChanges( ); |
/* dsOrderTables.i -- include file for Temp-Table definitions */
DEFINE TEMP-TABLE ttOrder FIELDS (...) INDEX OrderNum IS UNIQUE PRIMARY OrderNum. DEFINE TEMP-TABLE ttOLine FIELDS (...) BEFORE-TABLE ttOlineBefore INDEX orderline IS UNIQUE PRIMARY Ordernum Linenum. |
/* dsOrderDef.i -- include file definition of DATASET dsOrder. */
DEFINE DATASET dsOrder FOR ttOrder, ttOLine DATA-RELATION OrderLine FOR ttOrder, ttOLine RELATION-FIELDS (OrderNum, OrderNum). |
{OrderTables.i}
{OrderDS.i} DEFINE INPUT-OUTPUT PARAMETER DATASET FOR dsOrder. DEFINE VARIABLE hSrcOline AS HANDLE NO-UNDO. DEFINE VARIABLE returnValue AS LOGICAL NO-UNDO. DEFINE DATA-SOURCE srcOline FOR Orderline. hSrcOline = DATA-SOURCE srcOline:HANDLE. BUFFER ttOLine:ATTACH-DATA-SOURCE(hSrcOline). FOR EACH ttOlineBefore TRANSACTION: returnValue = BUFFER ttOlineBefore:SAVE-ROW-CHANGES("Orderline") NO-ERROR. END. DELETE OBJECT hSrcOline. RETURN. |