R
rn5a
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.SelectCommand = New SqlCommand("spViewOrder",
sqlConn)
sqlDapter.SelectCommand.CommandType =
CommandType.StoredProcedure
Try
With sqlDapter.SelectCommand
.Parameters.Add("@UserID", SqlDbType.Int).Value =
UserID
.Parameters.Add("@OrderID", SqlDbType.Int).Value =
OrderID
End With
sqlConn.Open()
If (sqlDapter.SelectCommand.ExecuteReader.HasRows) 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.ViewOrder(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?
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.SelectCommand = New SqlCommand("spViewOrder",
sqlConn)
sqlDapter.SelectCommand.CommandType =
CommandType.StoredProcedure
Try
With sqlDapter.SelectCommand
.Parameters.Add("@UserID", SqlDbType.Int).Value =
UserID
.Parameters.Add("@OrderID", SqlDbType.Int).Value =
OrderID
End With
sqlConn.Open()
If (sqlDapter.SelectCommand.ExecuteReader.HasRows) 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.ViewOrder(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?