close

using (OleDbConnection conn = new OleDbConnection(DbConnectionString))
{             
        OleDbCommand cmd = new OleDbCommand(sqlquery, conn);
        OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
        OleDbCommandBuilder cmdb = new OleDbCommandBuilder(adapter);

        conn.Open();

       adapter.UpdateCommand = cmdb.GetUpdateCommand(); //此行在下行之前

        OleDbTransaction transaction = conn.BeginTransaction();
        

         try
          {
                         cmdb.UpdateCommand.Transaction = transaction;     
                affRow = adapter.Update(dt);
                transaction.Commit();           }
          catch (DBConcurrencyException e2)      //無影響筆數
          {
                affRow = 0;

          }
          catch (OleDbException e3)
          {
                affRow = e3.ErrorCode;

                transaction.Rollback();
          }
}

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 11 的頭像
    11

    冠霖的部落格

    11 發表在 痞客邦 留言(0) 人氣()