hey i m creating a page for seat reservation for online ticketing.... i want my booked seats whose status is1 shud turn green and unbooked wih status 0 shud remain red...
i m facing problem in object of data reader ...i ve to create array for data reader object so that it cud store all seats value 1 to 50...but the error saying out of bonds is occuring....following is my snippet...pls help

public partial class Default6 : System.Web.UI.Page
    public static int seats;
    int bookedseats;
    string query;
     int[] array = new int[50];

     string strcon = System.Configuration.ConfigurationManager.ConnectionStrings["online_ticketing3ConnectionString"].ConnectionString;
     protected void Page_Load(object sender, EventArgs e)

         bookedseats = System.Convert.ToInt32(Label19.Text);
         Label14.Text = Request.QueryString["value"];
         //Label18.Text = Request.QueryString["value"];
         SqlConnection conbal;
         SqlCommand cmdbal;
         SqlDataReader reabal;
         query = "select top 49 seat_status from seat_info,movie_info,hall_info";
         conbal = new SqlConnection(strcon);
         cmdbal = new SqlCommand();
         cmdbal.Connection = conbal;
         cmdbal.CommandText = query;
         reabal = cmdbal.ExecuteReader();
                 for (int i =0; i < 50; ++i)
                 string b;
                 if (reabal.Read())
                     b = reabal[i].ToString();
                     int status;
                     status = System.Convert.ToInt32(b);
                     if (status == 1 && i == 0 )
                         ImageButton51.ImageUrl = "~/green.bmp";

                     else if (status == 1 && i == 1)
                         ImageButton52.ImageUrl = "~/green.bmp";

                     else if (status == 1 && i == 6)
                         ImageButton53.ImageUrl = "~/green.bmp";



Edited by __avd: Added [code] tags.

7 Years
Discussion Span
Last Post by dnanetwork

Try taking the second (CODE) out of the beginning of your code segment and add it at the end with a "/" in front of the "CODE" part.

Makes it easier to read the code snippet :)

Edited by mike_2000_17: Fixed formatting


you seem to have a 50 element array and your loop is running from 0 to 49 (50 elements) but you're only selecting the top 49 in your SQL statement. Is the last iteration of the loop the problem? What point does it break at if you debug it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.