Execution of two SqlDataReader

B

Bnob

Here is my code :

'G_myConnection is a global SqlConnection
' the table VACDES , AGENDA are in the same Database
..
..
Monsql = "SELECT * FROM VACDES WHERE NUM=" & G_Num & " ORDER BY
NUM_MOIS"
cmd1 = New SqlCommand(Monsql, G_myConnection)
dr1 = cmd1.ExecuteReader

While dr1.Read
Monsql = "select SEM from AGENDA where DATE1=" & lDate
cmd2 = New SqlCommand(Monsql, G_myConnection)
dr2 = cmd2.ExecuteReader

While dr2.Read
dim toto as string = dr1.Item("myField")
.... my code
End While

drJoursFerieWeek.Close()
end while

dr1.close
..
..
..


But I have this error message when I excute "dr2 = cmd2.ExecuteReader"
:"There is already an open DataReader associated with this Connection
which must be closed first."

Any idea to do two SqlDataReader in same time ?
 
T

Teemu Keiski

Hi,

if you use readers this way (nested), they need to have separate database
connection. And to note: this will change in .NET v2.0 when there can be
more than one active resultset per connection, but unfortunately this limit
is there for v1.0 and v1.1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top