Sunday, September 21, 2008

SQL TRANSACTION

The below code perform sql transaction in VB.NET. We can use this code in C# also by making only some changes.


Try
con.Open()
trans = con.BeginTransaction
com.Transaction = trans
com.Connection = con

strSql = "Insert into Departments values('005','ABC')"
db.Save(strSql, com)

strSql = "Update Departments set department_name='EF' where department_code='002"
db.Save(strSql, com)
trans.Commit()
Catch ex As Exception
MsgBox(ex.Message)
trans.Rollback()
Finally
con.Close()
End Try

No comments: