title: Command.ExecuteScalar always return null while Stored Procedure in Management Studio runs fine
body: <p>I have the following SQL stored procedure with one input parameter and one out parameter.</p>
  <pre><code>CREATE PROCEDURE [dbo].[spCanUserEdit]
  (
  @username nvarchar(255)
  )
  AS
  BEGIN
  SET NOCOUNT ON;
  
  DECLARE @CanEdit bit
  
  SELECT
      @CanEdit = CanUserEdit
  FROM tblUsers
  WHERE username = LOWER(@username)
  RETURN SELECT @CanEdit
  END
  GO
  </code></pre>
  <p>In the stored procedure above <code>CanUserEdit</code> column in <code>tblUsers</code> is bit type column and with default value to 0. Now when I execute this procedure in Management Studio it runs fine but when i use <code>command.ExecuteScalar()</code> in my C# code, it always returns <code>null</code>. Could anyone please tell me what I am doing wrong here.</p>
  <p>Following is my C# method</p>
  <pre><code>public static bool CanUserEdit(string userName)
  {
      using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString))
      {
          using (SqlCommand cmd = new SqlCommand())
          {
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.CommandText = &quot;spCanUserEdit&quot;;
              cmd.Connection = conn;
  
              cmd.Parameters.Add(new SqlParameter(&quot;@username&quot;, userName));
  
              conn.Open();
              bool canEdit = (bool)cmd.ExecuteScalar();
  
              return canEdit;
          }
      }
  }
  </code></pre>