ToBe

ToBe

  • NA
  • 164
  • 94.4k

Invalid attempt to read when no data is present

Feb 28 2013 7:50 AM
Hi I have a problem when try to read from database it's always stop the Debugger and give this msg: "Invalid attempt to read when no data is present"
and this is my code:
 SqlDataReader dr;


         
            dr=cmd.ExecuteReader  ();


            dr.Read();


            int xx = int.Parse ( dr[0].ToString());
            Response.Write(xx);


            dr.Close();
           
            for (i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected == true)
                {
                    cmd = new SqlCommand();
                    cmd.CommandText = "insert into tbltts values ('" +CheckBoxList1.Items[i].Text + "'," + xx + ")";
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();
                }
            }




            con.Close();




        }

Answers (2)