HighTechTalks DotNet Forums  

Reader alreay associated with command error

Dotnet Data Tools microsoft.public.dotnet.datatools


Discuss Reader alreay associated with command error in the Dotnet Data Tools forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Crash
 
Posts: n/a

Default Reader alreay associated with command error - 12-19-2005 , 01:58 PM






Hello,

I've searched and seen this question posted many times, but all the answers
are about the same and none work for me.

I have 2 SQL commands, and 2 data readers. Here is the code block:
cmd.CommandText = "Select * From ServiceDepartments order By Department"
reader = cmd.ExecuteReader()

while reader.read()
ctr = ctr + 1
Departments(ctr-1) = reader("Department")
DepID(ctr-1) = reader("ID")

'Write the javascript condition for the department
Response.Write (" if (Departments[Departments.selectedIndex].value ==
""" & reader("id") & """) {" & vbcrlf)


'*** PROBLEM HERE!!!
cmd2.commandText = "Select * From Skills Where ServiceDepID = " &
reader("id") & " order By SkillName"
reader2 = cmd2.executeReader()

'DO STUFF WITH Reader2

reader2.Close() 'Reader Closed!
end while

As soon as the code loops the first time on Reader2/Cmd2 I get the following
error:

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

But there is not an open reader! Ok, "reader" is open, but it is not
associated with cmd2. What am I supposed to be doing here?

Thanks in advance,

Craig



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.