The following code resides in a VB class file name GetOrder.vb (this
class file exists in the App_Code directory):
Namespace Shop
Public Class Orders
Public Function ViewOrder(ByVal UserID As Integer, ByVal
OrderID As Integer) As SqlDataAdapter
Dim sqlDapter As SqlDataAdapter
Dim sqlConn As SqlConnection
sqlConn = New SqlConnection(" ......")
sqlDapter = New SqlDataAdapter
sqlDapter.Selec tCommand = New SqlCommand("spV iewOrder",
sqlConn)
sqlDapter.Selec tCommand.Comman dType =
CommandType.Sto redProcedure
Try
With sqlDapter.Selec tCommand
.Parameters.Add ("@UserID", SqlDbType.Int). Value =
UserID
.Parameters.Add ("@OrderID", SqlDbType.Int). Value =
OrderID
End With
sqlConn.Open()
If (sqlDapter.Sele ctCommand.Execu teReader.HasRow s) Then
Return sqlDapter
Else
Return Nothing
End If
Catch ex As Exception
Throw ex
End Try
End Function
End Class
End Namespace
This is how an ASPX page named GetOrder.aspx accesses the above
function which returns a SqlDataAdapter:
<%@ Import Namespace="Shop " %>
'import other namespaces
Sub UserCart()
Dim dSet As DataSet
Dim boOrders As Orders
Dim sqlDapter As SqlDataAdapter
dSet = New DataSet
boOrders = New Orders
sqlDapter = boOrders.ViewOr der(iUserID, iOrderID)
sqlDapter.Fill( dSet)
End Sub
When I run the ASPX page, the following error gets generated:
There is already an open DataReader associated with this Command which
must be closed first.
pointing to the sqlDapter.Fill( dSet) line.
How do I overcome this error? 2 3180
Consume the data it is already getting or close the reader or use a
different adapter. The pattern used passes back is in the midst of a query
(how many rows) that is pulled by a reader.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA http://gregorybeamer.spaces.live.com
*************** *************** **************
Think outside the box!
*************** *************** **************
<rn**@rediffmai l.comwrote in message
news:11******** **************@ 45g2000cws.goog legroups.com...
The following code resides in a VB class file name GetOrder.vb (this
class file exists in the App_Code directory):
Namespace Shop
Public Class Orders
Public Function ViewOrder(ByVal UserID As Integer, ByVal
OrderID As Integer) As SqlDataAdapter
Dim sqlDapter As SqlDataAdapter
Dim sqlConn As SqlConnection
sqlConn = New SqlConnection(" ......")
sqlDapter = New SqlDataAdapter
sqlDapter.Selec tCommand = New SqlCommand("spV iewOrder",
sqlConn)
sqlDapter.Selec tCommand.Comman dType =
CommandType.Sto redProcedure
Try
With sqlDapter.Selec tCommand
.Parameters.Add ("@UserID", SqlDbType.Int). Value =
UserID
.Parameters.Add ("@OrderID", SqlDbType.Int). Value =
OrderID
End With
sqlConn.Open()
If (sqlDapter.Sele ctCommand.Execu teReader.HasRow s) Then
Return sqlDapter
Else
Return Nothing
End If
Catch ex As Exception
Throw ex
End Try
End Function
End Class
End Namespace
This is how an ASPX page named GetOrder.aspx accesses the above
function which returns a SqlDataAdapter:
<%@ Import Namespace="Shop " %>
'import other namespaces
Sub UserCart()
Dim dSet As DataSet
Dim boOrders As Orders
Dim sqlDapter As SqlDataAdapter
dSet = New DataSet
boOrders = New Orders
sqlDapter = boOrders.ViewOr der(iUserID, iOrderID)
sqlDapter.Fill( dSet)
End Sub
When I run the ASPX page, the following error gets generated:
There is already an open DataReader associated with this Command which
must be closed first.
pointing to the sqlDapter.Fill( dSet) line.
How do I overcome this error?
This line:
If (sqlDapter.Sele ctCommand.Execu teReader.HasRow s) Then
causes the DataReader to be created and opened.
What you should do is change the function to fill a dataset and return that,
rather than returning a DataAdapter. The DataSet can then be checked to see
if it contains any data or not. A DataReader is not needed here since you
have a DataAdapter which will do the work.
<rn**@rediffmai l.comwrote in message
news:11******** **************@ 45g2000cws.goog legroups.com...
The following code resides in a VB class file name GetOrder.vb (this
class file exists in the App_Code directory):
Namespace Shop
Public Class Orders
Public Function ViewOrder(ByVal UserID As Integer, ByVal
OrderID As Integer) As SqlDataAdapter
Dim sqlDapter As SqlDataAdapter
Dim sqlConn As SqlConnection
sqlConn = New SqlConnection(" ......")
sqlDapter = New SqlDataAdapter
sqlDapter.Selec tCommand = New SqlCommand("spV iewOrder",
sqlConn)
sqlDapter.Selec tCommand.Comman dType =
CommandType.Sto redProcedure
Try
With sqlDapter.Selec tCommand
.Parameters.Add ("@UserID", SqlDbType.Int). Value =
UserID
.Parameters.Add ("@OrderID", SqlDbType.Int). Value =
OrderID
End With
sqlConn.Open()
If (sqlDapter.Sele ctCommand.Execu teReader.HasRow s) Then
Return sqlDapter
Else
Return Nothing
End If
Catch ex As Exception
Throw ex
End Try
End Function
End Class
End Namespace
This is how an ASPX page named GetOrder.aspx accesses the above
function which returns a SqlDataAdapter:
<%@ Import Namespace="Shop " %>
'import other namespaces
Sub UserCart()
Dim dSet As DataSet
Dim boOrders As Orders
Dim sqlDapter As SqlDataAdapter
dSet = New DataSet
boOrders = New Orders
sqlDapter = boOrders.ViewOr der(iUserID, iOrderID)
sqlDapter.Fill( dSet)
End Sub
When I run the ASPX page, the following error gets generated:
There is already an open DataReader associated with this Command which
must be closed first.
pointing to the sqlDapter.Fill( dSet) line.
How do I overcome this error? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mark |
last post by:
Hi all, quick question , a DataView is
memory resident "view" of data in a data table therefore once populated you
can close the connection to the database. Garbage collection can then be
used to "clean up" the DataView once it is not referenced and will not
effect the number of connections to the database.
A DataReader on the other hand always maintains a connection to the database
and must be explicitly closed (Do not rely on garbage...
|
by: Maziar Aflatoun |
last post by:
Hi everyone,
I am working on the 'Delete' section of my program. What I need to do is
query my database and for every ID that it finds I want to remove a
file+ID.jpg from my file folder and update another table with that
information. However, I'm getting the following error message.
There is already an open DataReader associated with this Connection which
must be closed first.
Description: An unhandled exception occurred during the...
|
by: Grant |
last post by:
Hi,
I keep getting the following error message:
InvalidOperationException: There is already an open DataReader associated
with this Connection which must be closed first.
I have read up about it and realise that you can only have one DataReader
open on a Connection at a time, but don't know how to rewrite my code to work
properly.
|
by: Rykie |
last post by:
I have an application that constantly needs to read and write data to a
SQL box. For most of my read transactions I use a datareader. I
compiled a class that has all my datareader commands in it etc.
This works well, but every now and then a bunch of errors occurs,
relating to either the connection not being initialized, or reader
already associated with existing connection.
Now I have done everything I could think of to get rid of...
|
by: jason |
last post by:
Hi,
{asp .net 1.1, sp 2)
I am facing problems with multi users accessing the same page. There is a
datagrid in the webform. The "datareader already opened error/ object
reference not found" errors will occur randomly when multi users are
clicking page number (paging), any page number.
The connection object is declared private and connection is closed
| |
by: fniles |
last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader.
As I read data from tblA, I want to populate tblB. I use SQLDataReader for
both tables. I do not use thread.
When I ExecuteReader on tblB, I get the error "There is already an open
DataReader associated with this Connection which must be closed first."
How can I fix this error ?
For each DataReader, do I want to open and close the connection (in this
case adoCon) to avoid this error ?...
|
by: jimmy |
last post by:
Hi again,
sorry for posting two questions so close together but im working on a
school project which is due in soon and running into some difficulties
implementing the database parts. I have the code below which when
executed generates the following error message: 'There is already an
open datareader with this command which must be closed first'
Private Sub MainMenu_Load(ByVal sender As System.Object, ByVal e As
|
by: Johnny Jörgensen |
last post by:
I've got an error that I simply cannot locate:
I've got a form in which I use a datareader object to read information from
a db. After the read, I close the reader and I dispose of both the reader
and the command object (but don't close the connection which is public in
the solution).
The first time i open my form from a parent form, there is no problem.
Everything works fine. I then close down my form, and I dispose of the form.
|
by: BLUE |
last post by:
I've a TransactionScope in which I select some data and I want to do some
queries for each record retrieved with my select.
I'm using a DataReader and for each record I do factory.CreateCommand() and
then I execute the command, but I get the following exception message:
" There is already an open DataReader associated with this Command which
must be closed first. "
Searching on google I've found I've to create another connection, but...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |