public void UpdateTasks() { SqlTransaction transaction = null; try { if (_taskTable.Rows.Count == 0) { GetTask(); } DateTime dueDate = DateUtils.SqlUtcNow; _taskRow.DueDt = dueDate; TasksTD tasksDataSet = new TasksTD(); tasksDataSet.Merge(_taskTable); TasksTD.UpdateTasks(tasksDataSet, ref transaction); SqlUtils.CommitTransaction(transaction); GetTask(); Assert.AreEqual(dueDate, _taskRow.DueDt); } catch (Exception ex) { SqlUtils.RollbackTransaction(transaction); Assert.Fail(ex.Message); } }
/// <summary> /// Service callable code to Delete/Insert/Update Issues /// </summary> /// <param name="cd">A ClientDataSet of type IssuesCD</param> /// <returns>A IssuesCD ClientDataSet. If ALL OK contains updated data, if not contains the RowErrors</returns> public static IssuesCD UpdateIssues(IssuesCD cd) { if (cd == null || cd.Tables["Issues"] == null || cd.Tables["Issues"].Rows.Count == 0) { throw new Exception("The DataSet and/or DataTable is null or empty."); } TasksTD.TasksDataTable tt = new TasksTD.TasksDataTable(); IssuesCD.IssuesDataTable ct = new IssuesCD.IssuesDataTable(); foreach (IssuesRow modifiedRow in cd.Issues.Select("", "", DataViewRowState.ModifiedCurrent)) { ct.Clear(); // clear for next row to import ct.ImportRow(modifiedRow); // import single row into Table for merge tt.Merge(TasksTD.GetTask(modifiedRow.TaskId)); // populate with all current columns tt.Merge(ct, false, MissingSchemaAction.Ignore); // overlay with updated columns } TasksTD td = new TasksTD(); td.Tasks.BeginLoadData(); td.Tasks.Merge(cd.Issues, false, MissingSchemaAction.Ignore); td.Tasks.Merge(tt, false, MissingSchemaAction.Ignore); SqlTransaction transaction = null; try { TasksTD.UpdateTasks(td, ref transaction); SqlUtils.CommitTransaction(transaction); if (transaction.Connection != null && transaction.Connection.State == ConnectionState.Open) { transaction.Connection.Close(); } transaction.Dispose(); } catch (Exception ex) { SqlUtils.RollbackTransaction(transaction); throw ex; } return(cd); }