Mit Hilfe der Eigenschaft UpdateBatchSize kann eingestellt werden, wieviele Update-Befehle beim Updaten eines Datasets in die Datenbank zusammengefasst werden sollen.
DataAdapter and Batch Updates. In the previous version of ADO.NET, when updating a database with changes from a DataSet, the Update method of a DataAdapter performs updates to the database one row at a time.
As the method iterates through the rows in the specified DataTable, it examines each DataRow to see if the row has been modified. If the row has been modified, the method calls the appropriate UpdateCommand, InsertCommand or DeleteCommand, depending on the value of the RowState property for that row. Every row update involves a network round-trip to the database.
In ADO.NET 2.0, the DataAdapter exposes an UpdateBatchSize property. Setting the property to a positive integer value causes updates to the database to be sent as batches of the specified size. For example, setting the UpdateBatchSize to 10 will group 10 separate statements and submit them as a single batch. Setting the UpdateBatchSize to 0 will cause the DataAdapter to use the largest batch size that the server can handle. Setting it to 1 disables batch updates as rows are sent one at a time.
Event Behavior Changes with Batch Updates. The DataAdapter class has two update-related events i.e. RowUpdating and RowUpdated. In previous versions of ADO.NET, and when batch processing is disabled, each of these events is generated once for each row processed. RowUpdating is generated before the update occurs, and RowUpdated is generated after the database update is completed.
When batch processing is enabled, multiple rows are updated in a single database operation. Therefore, only one RowUpdated event occurs for each batch, whereas the RowUpdating event occurs for each row processed.
When batch processing is disabled, the two events are fired with one-to-one interleaving where one RowUpdating event and one RowUpdated event fire for a row, then one RowUpdating and one RowUpdated event fire for the next row, until all of the rows are processed.