Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2007, 02:11 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datareader Query

Hi,

Within asp.net 1.1 / vbnet I have created a function and used a datareader to grab some data from a database as per the code below :

Code:
 Function GetProdID() As System.Data.IDataReader

        Dim strConnString As String = ConfigurationSettings.AppSettings.Get("ConnectionString")
        strConnString = String.Format(strConnString, Server.MapPath("\db\nwguitars.mdb"))
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(strConnString)

        Dim queryString As String = "SELECT tblCartItems.intCartID, tblProducts.strProductName, "& _
        "tblCartItems.intProductID, tblType.strTypeDetails, tblCartItems.intQuantityOrder, "& _
        "tblProducts.intQuantityInStock FROM tblType INNER JOIN (tblProducts INNER JOIN tblCartItems ON tblProducts.intProductID = tblCartItems.intProductID) "& _
        "ON tblType.intTypeID = tblProducts.intTypeID WHERE [tblCartItems].[intCartID] = " & Session("CartID") & " ; "

        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        dbConnection.Open
        Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

        Return dataReader
    End Function
I want to be able to call one of the values (intProductID) from another function. What's the best way to do this from the datareader code - any examples would help, thanks ?


 
Old January 8th, 2007, 05:08 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Unfortunately, to be able to use the DataReader object you have to have an open connection to a data store, once its closed you lose the ability to read through the DataReader and in that regard it is pointless to pass a Datareader object around.

My advice would be to use a Datatable or Dataset as those are memory resident and will contain data after the connection ot the database is closed.

So what i might do is something like:

Function GetProdID() as DataTable
//Your code
Return dt
End Function

Function foo(ByVal dt as DataTable) as [datatype]
  Dim iID as Integer = dt.rows[n].item["intProductID"]
  Return [something]
End Function

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature





Similar Threads
Thread Thread Starter Forum Replies Last Post
datareader MunishBhatia ASP.NET 2.0 Professional 2 October 17th, 2007 07:05 AM
DataReader Query rsm42 ASP.NET 1.0 and 1.1 Basics 3 April 27th, 2007 12:02 PM
regarding datareader adityamadisetty VB.NET 1 May 8th, 2006 09:31 AM
DataReader truongnnhat ASP.NET 1.0 and 1.1 Basics 2 February 18th, 2005 12:41 AM
DataReader cjcd BOOK: Beginning ASP.NET 1.0 2 March 21st, 2004 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.