Friday, 15 August 2014

sql - insert record in multiple table using sqldataadapter and sqltransaction -



sql - insert record in multiple table using sqldataadapter and sqltransaction -

i'm trying insert record in multiple table @ time using sqldataadapter , sqltransaction. utilize next code. not working. help me plz....... tell me problem in code

dim cn new sqlconnection("data source=.\sqlexpress;initial catalog=amhsdb;integrated security=true") dim da new sqldataadapter dim ds new dataset dim trans sqltransaction dim tot integer public sub recordsave() tot = cint(tb3.text.trim) + cint(tb4.text.trim) + cint(tb5.text.trim) + cint(tb6.text.trim) dim yr string yr = now.year() seek cn.open() trans = cn.begintransaction() da.insertcommand.transaction = trans da.insertcommand = new sqlcommand("insert into[ftut_tbl] (roll_no,s_name,class,session,eng_i,ben,math,stu_wor,gra_tot) values ('" & tb1.text.trim & "','" & tb2.text.trim & "','nursery','" & yr & "','" & tb3.text.trim & "','" & tb4.text.trim & "','" & tb5.text.trim & "','" & tb6.text.trim & "','" & tot & "')", cn) da.insertcommand.executenonquery() da.dispose() da.insertcommand = new sqlcommand("insert into[fte_tbl] (roll_no,s_name,class,session) values ('" & tb1.text.trim & "','" & tb2.text.trim & "','nursery','" & yr & "')", cn) da.insertcommand.executenonquery() da.dispose() trans.commit() msgbox("rocord inserted!") grab ex exception trans.rollback() msgbox(ex.message) cn.close() end seek end sub

create insertcommand first, , assign transaction:

da.insertcommand = new sqlcommand("...") da.insertcommand.transaction = trans

and need commit transactions:

da.insertcommand.transaction.commit()

sql vb.net

No comments:

Post a Comment