Luckily, it's pretty easy:
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM wherever", conn);
conn.Open();
int count = (int)cmd.ExecuteScalar();
}
Obviously, you need to modify the SQL and provide
connString
, the usual exception handling is also missing from my sample.