M
m.fisher
Hi
I am looking at the starter kits from asp.net 1.1. I have read that a
datareader returned from a DAL should be closed. In the code below,
copied from the Commerce starter kit, how would the datareader be
closed? I know there is a .close() command, but where would it go.
Thanks
----------------
DAL
----------------
Public Function GetProductCategories() As SqlDataReader
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("CMRC_ProductCategoryList", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Execute the command
myConnection.Open()
Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Return the datareader result
Return result
End Function
---------------
..aspx page
---------------
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Obtain categoryId from QueryString
Dim categoryId As Integer = CInt(Request.Params("CategoryID"))
' Obtain products and databind to an asp:datalist control
Dim productCatalogue As ASPNET.StarterKit.Commerce.ProductsDB = New
ASPNET.StarterKit.Commerce.ProductsDB()
MyList.DataSource = productCatalogue.GetProducts(categoryId)
MyList.DataBind()
End Sub
I am looking at the starter kits from asp.net 1.1. I have read that a
datareader returned from a DAL should be closed. In the code below,
copied from the Commerce starter kit, how would the datareader be
closed? I know there is a .close() command, but where would it go.
Thanks
----------------
DAL
----------------
Public Function GetProductCategories() As SqlDataReader
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("CMRC_ProductCategoryList", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Execute the command
myConnection.Open()
Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Return the datareader result
Return result
End Function
---------------
..aspx page
---------------
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Obtain categoryId from QueryString
Dim categoryId As Integer = CInt(Request.Params("CategoryID"))
' Obtain products and databind to an asp:datalist control
Dim productCatalogue As ASPNET.StarterKit.Commerce.ProductsDB = New
ASPNET.StarterKit.Commerce.ProductsDB()
MyList.DataSource = productCatalogue.GetProducts(categoryId)
MyList.DataBind()
End Sub