0

I use two reader rdr1,rdr2
after usage of first reader i close that by rdr1.close();
then I used second reader but i found run time error which is illustrate below

There is already an open DataReader associated with this Command which must be closed first.

SqlDataReader rdr1 = ck1.ExecuteReader();
            while (rdr1.Read())
            {
                if (rdr1.HasRows)
                {
                    if (rdr1["Pno"].ToString() == pmemno.Text)
                    {
                        q1 = "delete from Principal where PID = '" + @pmemno.Text.ToString() + "'";
                        SqlCommand c1 = new SqlCommand(q1, cn);
                        c1.ExecuteNonQuery();
                    }
                    else { }
                }
            }
            rdr1.Close();
            rdr1.Dispose();

            SqlDataReader rdr2 = ck2.ExecuteReader();
            while (rdr2.Read())
            {
                if (rdr2.HasRows)
                {
                    if (rdr2["Addno"].ToString() == v2.ToString())
                    {
                        q2 = "delete from Address where Addno = '" + v2 + "'" + " and street = '" + paddr.Text.ToString() + "'";
                        SqlCommand c2 = new SqlCommand(q2, cn);
                        c2.ExecuteNonQuery();
                    }
                    else { }
                }

Please help me...

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by stbuchok
0

If you are using SQL 2005 or later try adding MultipleActiveResultSets=True to your connection string

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.