in my code i do serveral function which i realted to eachother, so if any of them fails ,so the rest should be Rollback, so i want to use transaction.any of these function has its own Connection and SQLCOMMAND, so how can i use transaction here , i just write a very simple of the code here
main Part
DeleteRec(id_CT,CoreNo);
InsertRec(id_CT,CoreNo,foudrow);
public void DeleteRec( int Argid_CT,int ArgCoreNo)
{
SqlCommand mySqlCommand=new SqlCommand();
CreateConn();
mySqlCommand= myConn.CreateCommand();
String Str="Delete * from TblCTVknee where id_CT="+Argid_CT + " and CoreNo="+ArgCoreNo;
mySqlCommand.CommandText=Str;
mySqlCommand.ExecuteNonQuery();
mySqlCommand.Dispose();
CloseConnection();
}
public void InsertRec(String ArgStr,String CTArg,DataRow[] ArgRow)
{
SqlCommand mySqlCommand=new SqlCommand();
CreateConn();
mySqlCommand= myConn.CreateCommand();
foreach ( DataRow myRowChild in ArgRow)
{
//Here i do other stuff
}
mySqlCommand.Dispose();
CloseConnection();
}
i want these two function should be related to eachother
, if i put them in one function i can do that, which is not good , because many part of function should be repeated in other functions also,so how should i do that
main Part
DeleteRec(id_CT,CoreNo);
InsertRec(id_CT,CoreNo,foudrow);
public void DeleteRec( int Argid_CT,int ArgCoreNo)
{
SqlCommand mySqlCommand=new SqlCommand();
CreateConn();
mySqlCommand= myConn.CreateCommand();
String Str="Delete * from TblCTVknee where id_CT="+Argid_CT + " and CoreNo="+ArgCoreNo;
mySqlCommand.CommandText=Str;
mySqlCommand.ExecuteNonQuery();
mySqlCommand.Dispose();
CloseConnection();
}
public void InsertRec(String ArgStr,String CTArg,DataRow[] ArgRow)
{
SqlCommand mySqlCommand=new SqlCommand();
CreateConn();
mySqlCommand= myConn.CreateCommand();
foreach ( DataRow myRowChild in ArgRow)
{
//Here i do other stuff
}
mySqlCommand.Dispose();
CloseConnection();
}
i want these two function should be related to eachother
, if i put them in one function i can do that, which is not good , because many part of function should be repeated in other functions also,so how should i do that