title: ExecuteScalar() always return NULL
body: <p>I am trying to return an integer from the database using ExecuteScalar(). However, when I run the query on the database itself, I get the correct answer, and c# gives me a 0 (Null) all the time. I know it returns a null because before i added <code>id = Convert.ToInt32(command.ExecuteScalar());</code> it would give me an error telling me to make sure NULL is handled. I am expecting it to return a 3 btw.</p>
  
  <pre><code> private int getFamilyId()
   {
      int id = 0;
      using (SqlConnection connection = new SqlConnection(Globaldata.ConnectionString))
      {
          using (SqlCommand command = new SqlCommand())
          {
              string sqlString = @"SELECT [Id] FROM [dbo].[FamilyDetails];";
              command.Connection = connection;
              command.CommandText = sqlString;
              try
              {
                  connection.Open();
                  id = Convert.ToInt32(command.ExecuteScalar());
              }
              catch (Exception e)
              {
                  MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK);
              }
              finally
              {
                  connection.Close();
              }
              return id;
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AxWwq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AxWwq.png" alt="This is what I get when I run it on the database"></a></p>