DbDataAdapter对象UpdataBatchSize属性批量修改

private void rowUpdated(object sender, SqlRowUpdatedEventArgs e)
      
{
         sb.Append(
"Rows: " + e.RecordsAffected.ToString() + "\r\n");
      }


      
private void btnUpdateBatch_Click(object sender, EventArgs e)
      
{
         
//event subsciption is normally placed in constructor but is here 
         
//to encapsulate the sample
         da.RowUpdated += new SqlRowUpdatedEventHandler(rowUpdated);
         ConnectionStringSettings pubs 
= ConfigurationManager.ConnectionStrings["PubsData"];
         DbConnection connection 
= new SqlConnection(pubs.ConnectionString);
         SqlCommand cmd 
= (SqlCommand)connection.CreateCommand();
         cmd.CommandType 
= CommandType.Text;
         cmd.CommandText 
= "SELECT * FROM Publishers";
         da.SelectCommand 
= cmd;
         DataSet pubsDataSet 
= new DataSet("Pubs");
         SqlCommandBuilder bldr 
= new SqlCommandBuilder(da);
         da.Fill(pubsDataSet, 
"publishers");
         
//Modify data here
         foreach (DataRow dr in pubsDataSet.Tables["publishers"].Rows)
         
{
            dr[
"pub_name"= "Updated Toys";
         }

         da.UpdateBatchSize 
=3;
         da.Update(pubsDataSet, 
"publishers");
         
//if event subscription is in the contructor, no need to 
         
//remove it here.
         da.RowUpdated -= new SqlRowUpdatedEventHandler(rowUpdated);
         MessageBox.Show(sb.ToString());
      }
原文地址:https://www.cnblogs.com/zwl12549/p/865089.html