Modular programing is right approach but it sometimes lead to problem which needs extra efforts and research. I have three database insert function like InsertName(),InsertAddress(),InsertPhoneNo()
take it as example. All these functions must execute if exception occurs in any of function no change will be made to database .
What I can do is merge all three in one and use sqltransaction.
InsertDetails()
{
using (SqlTransaction sqlTransaction = cn.BeginTransaction())
{
using (SqlCommand cm = new SqlCommand())
{
cm.Transaction = sqlTransaction;
InsertName();//Code to insert name
Insertaddress();//code to insert address
InsertPhoneNo();//code to insert phone no
}
sqlTransaction.Commit();
}
}
but the solution above is against my modular approach. Is it possible to bind multiple functions to one sql transaction without merging them , If not which is the best approach possible to achieve this.