在以前版本的 ADO
在ADO
執行非常大的批次可能會降低性能
使用 UpdateBatchSize 屬性
啟用了批量更新後
下面的過程演示如何使用 UpdateBatchSize 屬性
protected void btnUpdateAddress_Click(object sender
{
SqlDataAdapter EmpAdapter = new SqlDataAdapter();
DataTable EmpDT = new DataTable();
SqlConnection DBConSelect = new SqlConnection();
SqlConnection DBConUpdate = new SqlConnection();
SqlCommand SelectCommand = new SqlCommand();
SqlCommand UpdateCommand = new SqlCommand();
// Using different connection objects for select and updates from the
// Northwind database
DBConSelect
ConfigurationManager
DBConUpdate
ConfigurationManager
// Reading all records from the Employees table
SelectCommand
SelectCommand
SelectCommand
UpdateCommand
UpdateCommand
UpdateCommand
SqlParameter AddressParam;
AddressParam = new SqlParameter(
SqlDbType
SqlParameter CityParam;
CityParam = new SqlParameter(
SqlParameter RegionParam;
RegionParam = new SqlParameter(
SqlParameter CountryParam;
CountryParam = new SqlParameter(
SqlDbType
UpdateCommand
UpdateCommand
UpdateCommand
UpdateCommand
// Setting up Data Adapter with the Select and Update Commands
// The Select command will be used to retrieve all employee
// information from the Northwind database and the Update command
// will be used to save changes back to the database
EmpAdapter
EmpAdapter
EmpAdapter
DBConSelect
// Looping through all employee records and assigning them the new
// address
foreach (DataRow DR in EmpDT
{
DR[
DR[
DR[
DR[
}
// Adding an event handler to listen to the RowUpdated event
// This event will will fire after each batch is executed
EmpAdapter
lblCounter
EmpAdapter
// It is important to set this property for batch processing of
// updated records since batch updates are incapable of
// updating the source with changes from the database
UpdateCommand
try
{
DBConUpdate
EmpAdapter
}
catch (Exception ex)
{
lblCounter
}
finally
{
if (DBConUpdate
{
DBConUpdate
}
}
}
private void OnRowUpdated(object sender
{
lblCounter
args
}
From:http://tw.wingwit.com/Article/program/net/201311/12203.html