Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to add seat numbers selected by a single user into the database.
C#
void BindSeats()
   {
       Label14.Text = chargePerSheet.ToString();
       string sel = String.Join(",", (from b in objEntities.BookingDetails
                                      join s in objEntities.SeatDetails on b.BookingID equals s.BookingID
                                      where b.TourID == tourID
                                      select s.SeatID).ToArray());
       ClientScript.RegisterStartupScript(this.GetType(), "Init", "init([" + sel + "]);", true);

   }


getting an error like 'object reference not set' the code is like:

C#
protected void btnSubmit_Click(object sender, EventArgs e)
   {
       paymentmethod();
       sendMail();

       StarBusModel.BookingDetail objBooking = new StarBusModel.BookingDetail();
       objBooking.TourID = tourID;
       objBooking.Name = Label11.Text;
       objBooking.Phone = TextBox2.Text;
       objBooking.Amount = Convert.ToDecimal(Request.Form[Label14.ClientID]);
       string[] seats = Request.Form[Label13.ClientID].Split(new char[] { ',' });
       for (int i = 0; i < seats.Length; i++)
           objBooking.SeatDetails.Add(new StarBusModel.SeatDetail() { SeatID = Convert.ToInt32(seats[i]) });
       objEntities.BookingDetails.AddObject(objBooking);
       objEntities.SaveChanges();
       BindSeats();




       Response.Redirect("thankyou.aspx");
Posted
Updated 1-May-13 20:55pm
v3
Comments
Richard C Bishop 1-May-13 12:25pm    
You need to debug and see where the exception is being thrown. Once you have done that, it will be clear that you are using an object that you did not instantiate.
degrader404 1-May-13 12:34pm    
actually i want to add two distinct numbers in my database that holds values for tickets selected
Richard C Bishop 1-May-13 12:35pm    
See my solution, it is what you need.
degrader404 1-May-13 12:45pm    
still getting the same error:Object reference not set to an instance of an object.
Richard C Bishop 1-May-13 12:47pm    
Debug again and see where it is coming from now. My guess it is coming from "objEntities". You never instantiate that object either.

1 solution

It is stemming from "string[] seats = """. You never instantiated a string array. It should look like this:
C#
string[] seats = new string[1];

Then you can assign it the value you have.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900