Validation method error
<p>I have the following method to ensure that an entered username does not already exist.</p>

<pre><code>protected void checkUsername(object source, ServerValidateEventArgs args)
{
    string connString = "Data Source=server;Initial Catalog=database;User Id=username;Password=password;";
    string cmdText = "SELECT COUNT(*) FROM igs_users WHERE username = @username";

    using(SqlConnection conn = new SqlConnection(connString))
    {
        conn.Open();
        using(SqlCommand cmd = new SqlCommand(cmdText, conn))
        {
            cmd.Parameters.AddWithValue("@username", username);
            Int32 count = (Int32)cmd.ExecuteScalar();

            args.IsValid = true;
        }
    }
}
</code></pre>

<p>When I run it, I get the following error.</p>

<p>System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.
  Source=System.Data</p>

<p>The debugger gives me this error for the below line.</p>

<pre><code>Int32 count = (Int32)cmd.ExecuteScalar();
</code></pre>

<p>Any idea what's wrong with this code?</p>
