次の 2 つのコード ブロックのいずれかを使用する正当な理由があるかどうか、誰か教えていただけますか?
using (SqlTransaction mySqlTransaction = mySqlConnection.BeginTransaction)
{
using (SqlCommand mySqlCmd =
new SqlCommand("First of many SQL statements here", mySqlConnection, mySqlTransaction)
{
mySqlCmd.Parameters.Add("@MyFirstParm", SqlDbType.Int).Value = myFirstVal;
mySqlCmd.ExecuteNonQuery();
}
using (SqlCommand mySqlCmd =
new SqlCommand("Second of many SQL statements here", mySqlConnection, mySqlTransaction)
{
mySqlCmd.Parameters.Add("@MySecondParm", SqlDbType.Int).Value = mySecondVal;
mySqlCmd.ExecuteNonQuery();
}
.
.
.
sqlTransaction.Commit();
}
対。
using (SqlTransaction mySqlTransaction = mySqlConnection.BeginTransaction)
{
using (SqlCommand mySqlCmd = new SqlCommand("", mySqlConnection, mySqlTransaction)
{
mySqlCmd.Parameters.Add("@MyFirstParm", SqlDbType.Int).Value = myFirstVal;
mySqlCmd.Parameters.Add("@MySecondParm", SqlDbType.Int).Value = mySecondVal;
mySqlCmd.CommandText = "First of many SQL statements here";
mySqlCmd.ExecuteNonQuery();
mySqlCmd.CommandText = "Second of many SQL statements here";
mySqlCmd.ExecuteNonQuery();
.
.
.
}
sqlTransaction.Commit();
}