Featured post
c# - Transactions in Typed DataSets -
have typed dataset several related tables, , relations defined between tables. process datafeed, i'm adding, modifying, , removing records, calling update on each table.
requests reapprovals userrole requestid ----- requestid ----- roleid reason roleid ----/ userid
the reason using typed dataset have check existing data determine whether i'm adding, modifying, or removing records... need full dump of i'm working (the alternative 10,000 queries against database process records 1 one).
i want transactional support, i'm not seeing way typed datasets. example, i'm creating new request when create new reapproval. if reapproval fails update, don't want keep request.
putting update calls under transactionscope
mean if record fails, fail. not want.
how commit or roll related rows in typed dataset?
you can use regular transactions , achieve transaction feature tableadaptermanager in below examples.
first approach use regular transaction,
public void savewithtransacition() { dataset1tableadapters.table1tableadapter tatbl1 = new dataset1tableadapters.table1tableadapter(); dataset1tableadapters.table2tableadapter tatbl2 = new dataset1tableadapters.table2tableadapter(); sqltransaction st = null; sqlconnection sc = new sqlconnection("ur conneciton string"); try { sc.open(); st = sc.begintransaction(); tatbl1.transaction = st; tatbl2.transaction = st; st.commit(); } catch (system.exception ex) { st.rollback(); throw ex; } }
second..with table adapter manager..
public void savewithmanager() { dataset1tableadapters.tableadaptermanager mgr1 = new dataset1tableadapters.tableadaptermanager(); dataset1tableadapters.table1tableadapter tatbl1 = new dataset1tableadapters.table1tableadapter(); dataset1tableadapters.table2tableadapter tatbl2 = new dataset1tableadapters.table2tableadapter(); mgr1.table1tableadapter = tatbl1; mgr1.table2tableadapter = tatbl2; mgr1.updateorder = dataset1tableadapters.tableadaptermanager.updateorderoption.insertupdatedelete; mgr1.updateall(this); }
with option can create tamanagers group of tables save. if want 1 group save , if fail.
- Get link
- X
- Other Apps
Comments
Post a Comment