title: Read Integer values via Reader.(Sql-server)
body: <pre><code>con.Open();
  cmd = new SqlCommand("USE PRODUCTS SELECT BOUGHT FROM " +
                       DropDownList1.SelectedItem.Text +
                       " WHERE ID = @ID", con);
  cmd.Parameters.Add("ID", SqlDbType.Int).Value = DropDownList2.SelectedIndex;
  int i = cmd.ExecuteReader().GetInt32(0);
  con.Close();
  </code></pre>
  
  <p>I can't read integer values with reader like this. I get runtime error System.InvalidOperationException. What is wrong with my code ? if you can't find the mistake, can you explain how can i read integer values with reader ? By the way this part of code gives the error:</p>
  
  <pre><code>int i = cmd.ExecuteReader().GetInt32(0);
  </code></pre>