473,507 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Execution of two SqlDataReader

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 ?

--
Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com

Nov 18 '05 #1
1 1489
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

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Bnob" <bn**@bluewin.ch> wrote in message
news:mn***********************@bluewin.ch...
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 ?

--
Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
536
by: Ricola ! | last post by:
Why do I say: SqlDataReader dr; instead of SqlDataReader dr = new SqlDataReader();
7
2344
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code:...
3
5866
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
1
3245
by: Arvind P Rangan | last post by:
Hi All, How do you get all the values of a sqldatareader if it contains multiple resultset. Using sqldatareader.nextresult and sqldatareader.read e.g. While sqldatareader.read ' If not...
4
2878
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data...
1
1420
by: me | last post by:
Why is SqlDataReader not present in visual studios Toolbox->Data where I find components like DataSet? Most examples in books and in vs.net are based on datasets but using disconnected tables seems...
8
2059
by: bidllc | last post by:
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it resides. This is the function I'm calling:...
4
2356
by: mimi | last post by:
Hi Please help me out, I can't find a way to close a sqldatareader when error occur at statement cmd.ExecuteReader(). I can't close it in catch because it is local in try scope and I can't...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.