i have to insert in two tables with single transaction, query which have to implement are below. secondly getting exception at SqlDataReader read = comm.ExecuteR
You might want to consider switching to using TransactionScope which is then used implicitly for all commands within it. You'd use it something like:
using(var scope = new TransactionScope())
{
using(var conn = new SqlConnection(/*...*/))
{
//As many nested commands, etc, using the above connection.
//but don't need to create a SqlTransaction object nor
//in any way reference the scope variable
}
scope.Complete();
}
problem is you execute cmd1 on the same connection as cmd so there is an open transaction on that connection but you don't set cmd1.Transaction ... so solution would be to
cmd1.Transaction = transaction;
before
cmd1.ExecuteNonQuery();