예제 #1
0
 public void Update <TDataTable>(UpdateErrorHandler errorHandler)
     where TDataTable : DataTable, new()
 {
     try {
         Update <TDataTable>(null, errorHandler);
     } catch {
         throw;
     }
 }
예제 #2
0
 public void Update <TDataTable>(string applicationName, UpdateErrorHandler errorHandler)
     where TDataTable : DataTable, new()
 {
     try {
         string tableName = typeof(TDataTable).Name.Replace("DataTable", string.Empty);
         _SingleLock[tableName].WaitOne();
         try {
             TDataTable sourceTable = _RxlDataSet.Tables[tableName] as TDataTable;
             if (sourceTable == null)
             {
                 return;
             }
             string selectCommandText = string.Format("SELECT * FROM {0}", tableName);
             if (selectCommandText.Length == 0)
             {
                 throw new ApplicationException(string.Format("Command text for table '{0}' has not yot been set in the design time.", tableName));
             }
             try {
                 CreateTable(applicationName, tableName);
                 using (SqlConnection connection = new SqlConnection(RxlConfiguration.GetCurrent().GetConnectionString(applicationName))) {
                     using (SqlCommand selectCommand = new SqlCommand(selectCommandText, connection)) {
                         selectCommand.CommandTimeout = 0;
                         using (SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommand)) {
                             using (SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter)) {
                                 dataAdapter.InsertCommand = commandBuilder.GetInsertCommand(true).Clone();
                                 dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand(true).Clone();
                                 dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true).Clone();
                             }
                             connection.Open();
                             UpdateInternal(dataAdapter, DataViewRowState.Deleted, sourceTable, errorHandler);
                             UpdateInternal(dataAdapter, DataViewRowState.Added, sourceTable, errorHandler);
                             UpdateInternal(dataAdapter, DataViewRowState.ModifiedCurrent, sourceTable, errorHandler);
                         }
                     }
                 }
                 sourceTable.AcceptChanges();
             } catch {
                 sourceTable.RejectChanges();
                 throw;
             }
         } catch {
             throw;
         } finally {
             _SingleLock[tableName].Set();
         }
     } catch {
         throw;
     }
 }
예제 #3
0
 private void UpdateInternal(SqlDataAdapter dataAdapter, DataViewRowState recordStates, DataTable sourceTable, UpdateErrorHandler errorHandler)
 {
     try {
         while (true)
         {
             DataRow[]        changedRows = sourceTable.Select(null, null, recordStates);
             ErrorHandlerArgs args        = null;
             try {
                 SqlRowUpdatedEventHandler rowUpdated = delegate(object sender, SqlRowUpdatedEventArgs e) {
                     args = new ErrorHandlerArgs(sourceTable.TableName, e.Row, recordStates, e.Errors);
                 };
                 dataAdapter.RowUpdated += rowUpdated;
                 dataAdapter.Update(changedRows);
                 break;
             } catch {
                 if (errorHandler == null)
                 {
                     throw;
                 }
                 errorHandler(args);
                 if (args.Action == ErrorHandlingAction.ThrowError)
                 {
                     throw;
                 }
             }
         }
     } catch {
         throw;
     }
 }