I would like to insert a function in my code which is begin,commit, and rollback trans because the data is prone to errors. my code is this:
clsDBConnect dbConn = new clsDBConnect();
SqlCommand CMD;
SqlDataReader Reader;
private void Save()
{
CMD = new SqlCommand("SELECT * FROM tblEmployees", dbConn.connection);
Reader = CMD.ExecuteReader();
while (Reader.Reader())
{
while(variable1 != variable2)
{
//Lots of CMD.ExecuteNonQuery();
//Lots of Reader
//Lots of computation
variable1 += 1;
}
}
}
How can I rollback inserts and updates when error occurs during the loop?
Thanks!