A
Andrew Robinson
Are these two equivalent? Is one better than the other? I tend to go with #1
but started wondering....
Thanks,
1:
using (SqlConnection cn = new SqlConnection(DataConnection))
using (SqlCommand cm = new SqlCommand("ItemCount", cn)) {
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@Count", SqlDbType.Int);
cm.Parameters["@Count"].Direction = ParameterDirection.Output;
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
return (int)cm.Parameters["@Count"].Value;
}
2:
int count;
using (SqlConnection cn = new SqlConnection(DataConnection))
using (SqlCommand cm = new SqlCommand("ItemCount", cn)) {
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@Count", SqlDbType.Int);
cm.Parameters["@Count"].Direction = ParameterDirection.Output;
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
count = (int)cm.Parameters["@Count"].Value;
}
return count;
but started wondering....
Thanks,
1:
using (SqlConnection cn = new SqlConnection(DataConnection))
using (SqlCommand cm = new SqlCommand("ItemCount", cn)) {
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@Count", SqlDbType.Int);
cm.Parameters["@Count"].Direction = ParameterDirection.Output;
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
return (int)cm.Parameters["@Count"].Value;
}
2:
int count;
using (SqlConnection cn = new SqlConnection(DataConnection))
using (SqlCommand cm = new SqlCommand("ItemCount", cn)) {
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@Count", SqlDbType.Int);
cm.Parameters["@Count"].Direction = ParameterDirection.Output;
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
count = (int)cm.Parameters["@Count"].Value;
}
return count;