SqlTransaction transaction; con.Open(); transaction = con.BeginTransaction(); try { for (int i = 0; i < dtTemp.Rows.Count; i++) { SqlCommand cmd = new SqlCommand("insert command....", con,transaction); cmd.ExecuteNonQuery(); } transaction.Commit(); } catch (Exception Error) { }In above Part the only thing you have to care about is
SqlTransaction transaction;
con.Open();
transaction = con.BeginTransaction();
try {
cmd.ExecuteNonQuery();
transaction.Commit(); //whenever you call commit it means now finaly
//all execution will take place else rollback to catch
}
catch
{
transaction.Rollback();
}
No comments:
Post a Comment