473,471 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using two OleDbDataReaders at the same time

I have two OleDbDataReaders that I need to use at the same time. One of the
DataReadersis used inside a While loop. My code is as follows:

While eventreader.Read()

Response.Write(ControlChars.NewLine &
CStr(eventreader("eventdate")).PadRight(20) &
CStr(eventreader("eventname")).PadRight(32))

cmdregistered.CommandText = "SELECT SUM(attending) AS total FROM registered
WHERE eventid=" & CStr(eventreader("eventid"))

'eventreader.Close()

regreader = cmdregistered.ExecuteReader()

regreader.Read()

If regreader("total") Is System.DBNull.Value Then

Response.Write("0" & ControlChars.NewLine)

Else

Response.Write(CStr(regreader("total")) & ControlChars.NewLine)

End If

regreader.Close()

End While
When I use this code I recieve the following error:
There is already an open DataReader associated with this Connection which
must be closed first.
If I close the DataReader using the code which is commented out, I then
cannot reopen it. I did not have this problem when using an
OracleDataReader. The only solution I can think of would be to use a DataSet
rather than a DataReader for the first DataReader, but this would make
things less efficient. Does anyone know how to avoid this error? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
2 1050
Have you tried using TWO different connections - one for each
OleDbDataReader?

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have two OleDbDataReaders that I need to use at the same time. One of the
DataReadersis used inside a While loop. My code is as follows:

While eventreader.Read()

Response.Write(ControlChars.NewLine &
CStr(eventreader("eventdate")).PadRight(20) &
CStr(eventreader("eventname")).PadRight(32))

cmdregistered.CommandText = "SELECT SUM(attending) AS total FROM
registered WHERE eventid=" & CStr(eventreader("eventid"))

'eventreader.Close()

regreader = cmdregistered.ExecuteReader()

regreader.Read()

If regreader("total") Is System.DBNull.Value Then

Response.Write("0" & ControlChars.NewLine)

Else

Response.Write(CStr(regreader("total")) & ControlChars.NewLine)

End If

regreader.Close()

End While
When I use this code I recieve the following error:
There is already an open DataReader associated with this Connection which
must be closed first.
If I close the DataReader using the code which is commented out, I then
cannot reopen it. I did not have this problem when using an
OracleDataReader. The only solution I can think of would be to use a
DataSet rather than a DataReader for the first DataReader, but this would
make things less efficient. Does anyone know how to avoid this error?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
Hi Nathan,

Frankie is right - you'll have to have a connection per open datareader.
BTW, .net 2/Sql server 2005 will have a feature called MARS which will allow
many reads per connection.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have two OleDbDataReaders that I need to use at the same time. One of the
DataReadersis used inside a While loop. My code is as follows:

While eventreader.Read()

Response.Write(ControlChars.NewLine &
CStr(eventreader("eventdate")).PadRight(20) &
CStr(eventreader("eventname")).PadRight(32))

cmdregistered.CommandText = "SELECT SUM(attending) AS total FROM
registered WHERE eventid=" & CStr(eventreader("eventid"))

'eventreader.Close()

regreader = cmdregistered.ExecuteReader()

regreader.Read()

If regreader("total") Is System.DBNull.Value Then

Response.Write("0" & ControlChars.NewLine)

Else

Response.Write(CStr(regreader("total")) & ControlChars.NewLine)

End If

regreader.Close()

End While
When I use this code I recieve the following error:
There is already an open DataReader associated with this Connection which
must be closed first.
If I close the DataReader using the code which is commented out, I then
cannot reopen it. I did not have this problem when using an
OracleDataReader. The only solution I can think of would be to use a
DataSet rather than a DataReader for the first DataReader, but this would
make things less efficient. Does anyone know how to avoid this error?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #3

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

Similar topics

18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
5
by: John Dumais | last post by:
Hello, I have been trying to figure out how to write an array of doubles (in this specific case) to a binary stream without using a loop. What I have been doing is... foreach(double d in...
2
by: Nathan Sokalski | last post by:
I have two OleDbDataReaders that I need to use at the same time. One of the DataReadersis used inside a While loop. My code is as follows: While eventreader.Read() ...
14
by: Steve Teeples | last post by:
I don't understand why I cannot use a property to modify data within a struct. Can someone tell me why I get the error "Cannot modify the return value of "myData.TheData" because it is not a...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
2
by: Fabian Braennstroem | last post by:
Hi, I would like to delete a region on a log file which has this kind of structure: #------flutest------------------------------------------------------------ 498 1.0086e-03 2.4608e-04...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
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
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,...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.