title: Error : Index out of bound
body: <pre><code>protected void btnDownload_Click(object sender, EventArgs e)
      {
  
          //to request the name of the event from the listbox from Main.aspx
          string EventName = Request.QueryString["ename"];
  
          //Select event id statement
          //const string S = "SELECT EventName FROM Event WHERE EventID = @EventID";
          const string q = "SELECT EventID from Event WHERE EventName = @EventName"; 
          string eventid = "";
          using (SqlConnection c = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=PSeminar;Integrated Security=true;Trusted_Connection=Yes;MultipleActiveResultSets=true"))
          using (SqlCommand Command = new SqlCommand(q, c))
          {
              Command.Parameters.AddWithValue("@EventName", EventName);
  
              c.Open();
              using (SqlDataReader rdr = Command.ExecuteReader())
                  while (rdr.Read())
                  {
                      Command.CommandText = "Select * from Attendance where EventID=@EventID";
                      System.Text.StringBuilder sb = new System.Text.StringBuilder();
                      sb.Append(String.Format("\"{0}\",\"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\", \"{7}\"n",
                 rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5], rdr[6], rdr[7]));
                 // I have an error here(Index out of bound)
  
                      // to get event id from the Event name
                      eventid = rdr.GetString(0);
                      rdr.Close();
                      c.Close();
  
                      byte[] ar = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
                      Response.ClearContent();
                      Response.ClearHeaders();
                      Response.AddHeader("Content.Type", "application/octet-stream");
                      Response.AddHeader("Content-Length", ar.Length.ToString());
                      Response.AddHeader("Content-Disposition", "attachment; filename=download.csv");
                      Response.BinaryWrite(ar);
                      Response.Flush();
                      Response.End();
                  }
  
          }
  </code></pre>
  
  <p>The error was - "Index was outside the bounds of the array."
  I'm trying to download the file according to the event. so far i have done this much of codes. but i do not understand what the error means. pls explain to me what the error "Index was outside the bounds of the array means" and pls give me solutions. thanks</p>