Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 8th, 2007, 02:11 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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 ?


  #2 (permalink)  
Old January 8th, 2007, 05:08 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.