What is the best way to check if a record exists in a SQL Server table using C#?
<p>What is the best way?  To get a 1 or 0 back?  Or check if rows are available from a query?  I'm arguing for ExecuteScalar but interested in other answers why or why not.  </p>

<pre><code>//using DataReader.HasRows?
bool result = false;

var cmd = new SqlCommand("select foo, bar from baz where id = 123", _sqlConnection, _sqlTransaction);

cmd.CommandType = System.Data.CommandType.Text;

using (var r = cmd.ExecuteReader())
{
    if (r != null &amp;&amp; r.HasRows)
    {
        result = true;
    }
}

return result;

//or using Scalar?
bool result = false;

var cmd = new SqlCommand("if exists(select foo, bar from baz where id = 123) select 1 else select 0", _sqlConnection, _sqlTransaction);

cmd.CommandType = System.Data.CommandType.Text;

int i = (int) cmd.ExecuteScalar();
result = i == 1;
return result;
</code></pre>