title: SQL select from database in C#
body: <p>I have the following code in C#:</p>
  
  <pre><code>string query = "SELECT * FROM Zboruri WHERE cod_aeroport = " + country;
  
  using (var command = new SqlCommand(query, connection))
  {
      var list = new ArrayList();
      var reader = command.ExecuteReader();
  
      if (reader.HasRows)
      {
           while (reader.Read())
           {
               string data1 = reader.GetString(1);
               string data2 = reader.GetString(2);
               list.Add(cod_aeroport);
               list.Add(data1);
               list.Add(data2);
           }
      }
      else
      {
          string raspuns = "nu este info";
          list.Add(raspuns);
      }
  
      reader.Close();
      connection.Close();
      return list;
   }
  </code></pre>
  
  <p>My database table has these columns: </p>
  
  <pre><code>data1(numeric(18,0))
  data2(numeric(18,0))
  ...........
  </code></pre>
  
  <p>and it giving me error:</p>
  
  <blockquote>
    <p><em>Index was outside the bounds of the array.</em></p>
  </blockquote>
  
  <p>on this line of code:</p>
  
  <pre><code>string data2 = reader.GetString(2); 
  </code></pre>
  
  <p>How can I fix error?</p>