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

Update() public method

public Update ( DataRow dataRows ) : int
dataRows System.Data.DataRow
return int
        public int Update(DataRow[] dataRows)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataRows[]", ObjectID);
            try
            {
                int rowsAffected = 0;
                if (null == dataRows)
                {
                    throw ADP.ArgumentNull(nameof(dataRows));
                }
                else if (0 != dataRows.Length)
                {
                    DataTable dataTable = null;
                    for (int i = 0; i < dataRows.Length; ++i)
                    {
                        if ((null != dataRows[i]) && (dataTable != dataRows[i].Table))
                        {
                            if (null != dataTable)
                            {
                                throw ADP.UpdateMismatchRowTable(i);
                            }
                            dataTable = dataRows[i].Table;
                        }
                    }
                    if (null != dataTable)
                    {
                        DataTableMapping tableMapping = GetTableMapping(dataTable);
                        rowsAffected = Update(dataRows, tableMapping);
                    }
                }
                return rowsAffected;
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Same methods

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

Usage Example

Beispiel #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