传入实体执行(可添加 修改 删除)事务。
idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring(businessdbconnection)); bool result = true; try { dbhelper.begintransaction(); //主表 te_areamanager manager = new te_areamanager(dbhelper, userinfo); te_areaentity te_areaentity = manager.getobject(dbhelper.sqlsafe(eatxtarea_id)); manager.delete(te_areaentity);//子表 te_area_submanager submanager = new te_area_submanager(dbhelper, userinfo); te_area_subentity te_area_subentity = submanager.getobject(dbhelper.sqlsafe(eatxtarea_id)); submanager.delete(te_area_subentity);//事务提交 dbhelper.committransaction(); } catch(exception ex) {//事务回滚 dbhelper.rollbacktransaction(); result=false; } 可以传入sql语句执行事务idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring(businessdbconnection)); bool result = true; try { dbhelper.begintransaction(); string commandtext = delete from te_area where id= + dbhelper.sqlsafe(id); dbhelper.executenonquery(sqlstring); commandtext = delete from te_area_sub where id= + dbhelper.sqlsafe(id); dbhelper.executenonquery(commandtext); dbhelper.committransaction(); } catch(exception ex) { dbhelper.rollbacktransaction(); result=false; } 还可以同时传入实体,sql语句idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring(businessdbconnection)); bool result = true; try { dbhelper.begintransaction();//主表 te_areamanager manager = new te_areamanager(dbhelper, userinfo); te_areaentity te_areaentity = manager.getobject(dbhelper.sqlsafe(eatxtarea_id)); manager.delete(te_areaentity);//子表 te_area_submanager submanager = new te_area_submanager(dbhelper, userinfo); te_area_subentity te_area_subentity = submanager.getobject(dbhelper.sqlsafe(eatxtarea_id)); submanager.delete(te_area_subentity); //执行sql语句 string commandtext = delete from jintianda where id= + dbhelper.sqlsafe(id); dbhelper.executenonquery(commandtext); //事务提交 dbhelper.committransaction(); } catch(exception ex) { //事务回滚 dbhelper.rollbacktransaction(); result=false; }
