View Single Post
  #1 (permalink)  
Old June 3rd, 2011, 04:59 AM
Vayne Vayne is offline
Registered User
Join Date: Jun 2011
Posts: 7
Thanks: 1
Thanked 1 Time in 1 Post
Default Error: Invalid attempt to call Read when reader is closed


I have this sub which performs updates in successive function call. The reader object is closed only when the operation has been completed (after the while loop has ended), yet I get this error. Any suggestions?

	sub reset_slno()
		dim objCmd2 as new OleDBCommand()
		dim objReader2 as OleDBDataReader
		objCmd2.Connection = Conn
		objCmd2.CommandText = "SELECT * FROM tbl_civil_works"
			objReader2 = objCmd2.ExecuteReader
		catch ex as exception
			lblMessage.Text = ex.Message
		end try
                dim strSQL3 as String
		dim record_counter as Integer = 1
		while objReader2.Read()
			strSQL3 = "UPDATE tbl_civil_works SET codeno = " & record_counter
			record_counter = record_counter + 1
		end while

	end sub
Error details:

Source Error:

Line 227: dim record_counter as Integer = 1
Line 228:
Line 229: while objReader2.Read()
Line 230: dim strSQL3 as String = "UPDATE tbl_civil_works SET codeno = " & record_counter
Line 231: ExecuteStatement(strSQL3)

Source File: i:\inetpub\wwwroot\ecsite\civilworks1.aspx Line: 229
Reply With Quote
The Following User Says Thank You to Vayne For This Useful Post: