Execution of two SqlDataReader

  • Thread starter Thread starter Bnob
  • Start date Start date
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 ?
 
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
 
Back
Top