2
Answers

Invalid attempt to read when no data is present

ToBe

ToBe

11y
1.4k
1
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)