Friday, April 08, 2011

BulkUpdate With DAAB

 

Sample code:

 

private static Database db = DatabaseFactory.CreateDatabase("VTS01ConnectionString");

       public static void TestBulkUpate()
       {
           // Read all the customers in a dataset
           string selectSql = "SELECT  * FROM FormC_Transfer";
           DataSet customerDataSet = db.ExecuteDataSet(CommandType.Text, selectSql);

           // Modify Records
           foreach (DataRow dr in customerDataSet.Tables[0].Rows)
               dr["CategoryAddress"] += "_sdy ";

           // Create UpdateCommand
           string updateSql = "UPDATE FormC_Transfer SET CategoryAddress = @CategoryAddress WHERE CitemId=@CitemId";
           DbCommand updateCommand = db.GetSqlStringCommand(updateSql);
           db.AddInParameter(updateCommand, "CitemId", DbType.Int32, "CitemId", DataRowVersion.Current);
           db.AddInParameter(updateCommand, "CategoryAddress",
               DbType.String, "CategoryAddress", DataRowVersion.Current);

           // Execute Batch Update
           // Use zero to specify database
           // maximum batch update size
          // db.UpdateDataSet(customerDataSet, customerDataSet.Tables[0].TableName, null, updateCommand, null, UpdateBehavior.Standard);

 

db.UpdateDataSet(customerDataSet, customerDataSet.Tables[0].TableName, null, updateCommand, null, UpdateBehavior.Transactional,0);

0 Comments:

Post a Comment

<< Home