title: C# & SQL Server : Index was outside the bounds of the array
body: <p>I'm trying to get data from the SQL Server database but the error state that</p>
  
  <blockquote>
    <p>System.IndexOutOfRangeException: Index was outside the bounds of the array.</p>
  </blockquote>
  
  <p>This is my table</p>
  
  <p><a href="https://i.stack.imgur.com/Jl4jg.jpg" rel="nofollow noreferrer">TourDisplay</a></p>
  
  <p>My code:</p>
  
  <pre><code>SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=....;Integrated Security=True;Connect Timeout=30;User Instance=True;");
  
  SqlCommand cmd = new SqlCommand();
  SqlDataReader dtr;
  
  protected void Page_Load(object sender, EventArgs e)
  {
      cmd.Connection = conn;
      conn.Open();
  
      cmd.CommandText = "select BicycleType from TourDisplay order by TDateTime asc";
  
      dtr = cmd.ExecuteReader();
      bool temp = false;
  
      while (dtr.Read())
      {
          TBBicycleType.Text = dtr.GetString(0);
          TBBicycleType2.Text = dtr.GetString(1);
          temp = true;
      }     
  }
  </code></pre>
  
  <p>As you can see, the code should be fine because I got 3 data inside the table but I'm having problem on <code>GetString(1)</code>.</p>