System.Data.Common.DbDataAdapter.Update C# (CSharp) Method

Update() public method

public Update ( DataSet dataSet, string srcTable ) : int
dataSet System.Data.DataSet
srcTable string
return int
        public int Update(DataSet dataSet, string srcTable)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataSet, srcTable='{1}'", ObjectID, srcTable);
            try
            {
                if (null == dataSet)
                {
                    throw ADP.UpdateRequiresNonNullDataSet(nameof(dataSet));
                }
                if (string.IsNullOrEmpty(srcTable))
                {
                    throw ADP.UpdateRequiresSourceTableName(nameof(srcTable));
                }

                int rowsAffected = 0;

                System.Data.MissingMappingAction missingMapping = UpdateMappingAction;
                DataTableMapping tableMapping = GetTableMappingBySchemaAction(srcTable, srcTable, UpdateMappingAction);
                Debug.Assert(null != tableMapping, "null TableMapping when MissingMappingAction.Error");

                // the ad-hoc scenario of no dataTable just returns
                // ad-hoc scenario is defined as MissingSchemaAction.Add or MissingSchemaAction.Ignore
                System.Data.MissingSchemaAction schemaAction = UpdateSchemaAction;
                DataTable dataTable = tableMapping.GetDataTableBySchemaAction(dataSet, schemaAction);
                if (null != dataTable)
                {
                    rowsAffected = UpdateFromDataTable(dataTable, tableMapping);
                }
                else if (!HasTableMappings() || (-1 == TableMappings.IndexOf(tableMapping)))
                {
                    //throw error since the user didn't explicitly map this tableName to Ignore.
                    throw ADP.UpdateRequiresSourceTable(srcTable);
                }
                return rowsAffected;
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Same methods

DbDataAdapter::Update ( DataRow dataRows ) : int
DbDataAdapter::Update ( DataRow dataRows, DataTableMapping tableMapping ) : int
DbDataAdapter::Update ( DataSet dataSet ) : int
DbDataAdapter::Update ( DataTable dataTable ) : int

Usage Example

Esempio n. 1
0
 /// <summary>
 /// Calls the respective insert, update or delete command
 /// for each object in the specified collection to save the entity to the database.
 /// </summary>
 /// <param name="transaction">The transaction to save within.</param>
 /// <param name="entities">The entities to save.</param>
 /// <param name="batchSize">A value that enables or disables batch processing support, and specifies the number of commands that can be executed in a batch.
 /// <para>When the value is 0, the default, the adapter will use the largest batch size the server can handle.</para>
 /// <para>When the value is 1 batching is disabled.</para>
 /// <para>A value > 1 will send changes to the database using the specified batch size.</para></param>
 public virtual void Save(Transaction transaction, ICollection <T> entities, int batchSize = 0)
 {
     _batchSize = batchSize;
     if (_batchSize != 1)
     {
         InitializeDataAdapter(transaction);
         DataTable changes = CreateDataTable(entities);
         _dataAdapter.Update(changes);
         if (BatchComplete != null)
         {
             BatchComplete(this, new BatchCompleteEventArgs <T>(entities, changes.Rows));
         }
     }
     else
     {
         foreach (T entity in entities)
         {
             Save(transaction, entity);
         }
     }
 }
All Usage Examples Of System.Data.Common.DbDataAdapter::Update