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;
         conbal.Open();
         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";

                     }
                 }


             }
     }

Recommended Answers

All 3 Replies

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 :)

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?

++i => try i++

try to debug..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.