pratik pangire

pratik pangire

  • NA
  • 32
  • 14.1k

Error: There is no row at position 0

Jun 21 2018 1:44 AM
HI, i am currently working on a project, when i run the program, there is an error showing on button click event It says this:
 
Exception Details: System.IndexOutOfRangeException: There is no row at position 0.
  1. protected void btnAddCart_Click(object sender, EventArgs e)  
  2. {  
  3.       if (Session["Mycart"] == null)  
  4.       {  
  5.           ShoppingCart Mycart = new ShoppingCart();  
  6.          Session["Mycart"] = Mycart;  
  7.       }  
  8.       string Id = Request.QueryString["BookID"];  
  9.       Mycart =(ShoppingCart)Session["New"];  
  10.       String Query = "select * from BookData where BookID= '" + Id + "'";  
  11.       SqlCommand cmd = new SqlCommand(Query, con);  
  12.       SqlDataAdapter Da = new SqlDataAdapter(cmd);  
  13.       DataTable Dt = new DataTable();  
  14.       Da.Fill(Dt);  
  15.       DataRow row = Dt.Rows[0];  
  16.       Mycart.Insert(new CartItem(Int32.Parse(Id),  
  17.                               row["name"].ToString(),  
  18.                               row["author"].ToString(),  
  19.                               int.Parse(row["isbn"].ToString()),  
  20.                               row["language"].ToString(),  
  21.                               row["publisher"].ToString(),  
  22.                               row["Summary"].ToString(),  
  23.                               Double.Parse(row["price"].ToString()),  
  24.                               1)  
  25.                               );  
  26. }  
Please reply fast, its very urgent
 
thank you.

Answers (7)