you can do something like this...
1) create connection
2) create transaction
3) insert master record using that transaction (but do not commit it)
4) insert details record(s)
5) if all the thing is going good then commit the transaction or if error occurred rollback transaction.
something like this...
SqlConnection db = new SqlConnection("connstringhere");
SqlTransaction transaction;
db.Open();
transaction = db.BeginTransaction();
try
{
new SqlCommand("INSERT INTO master " +
"(Text) VALUES ('Row1');", db, transaction)
.ExecuteNonQuery();
for(int i =0; i<10;i++){
new SqlCommand("INSERT INTO details VALUES " +
"( " + i + ");", db, transaction)
.ExecuteNonQuery();
}
transaction.Commit();
}
catch (SqlException sqlError)
{
transaction.Rollback();
}
db.Close();