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();
}
}
留言列表