title: How do I use ExecuteScalar with a stored Procedure?
body: <p>I'm trying to get a count of column records in a Sql database and show the result in a MessageBox. </p>
  
  <p><strong>This is my code:</strong></p>
  
  <pre><code>public DataTable CheckIfNameExist(string name)
  {
      con = Connect();
      cmd = new SqlCommand();
      cmd.Connection = con;
      cmd.CommandText = "spCheckIfNameExist";
      cmd.Parameters.AddWithValue("@Name", SqlDbType.NVarChar).Value = name;
      MessageBox.Show(name);
  
      Int32 totalNames = (Int32) cmd.ExecuteScalar();
      string tNames = totalNames.ToString();
  
      MessageBox.Show(tNames);
  }
  </code></pre>
  
  <p><strong>And this is my sp:</strong></p>
  
  <pre><code>@Name nvarchar(50) = null
  As
  Begin
  SELECT COUNT(*) from OrdersSent where CustomerName LIKE @Name + '%'
  End
  </code></pre>
  
  <p><strong>Problem:</strong> </p>
  
  <p>It always returns 0.</p>