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

Hi,

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?

Code:
	sub reset_slno()
		
		dim objCmd2 as new OleDBCommand()
		dim objReader2 as OleDBDataReader
		objCmd2.Connection = Conn
		objCmd2.CommandText = "SELECT * FROM tbl_civil_works"
			
		try
			objCmd2.Connection.Open()
			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
			ExecuteStatement(strSQL3)	
			record_counter = record_counter + 1
		end while

		objReader2.Close()
		objCmd2.Connection.Close()		
		
	end sub
Error details:

Quote:
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: