Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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
  #1 (permalink)  
Old September 21st, 2004, 11:07 AM
Authorized User
Points: 447, Level: 7
Points: 447, Level: 7 Points: 447, Level: 7 Points: 447, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Adrian, MI, USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to get a function to return a recordset object

Code:
function funOne(sql)

  Dim rsOne

  Set rsOne = Server.CreateObject("ADODB.RecordSet")
  rsOne.Open sql, oConn

  Set funOne = rsOne

  rsOne.Close
  Set rsOne = Nothing

end function
Code:
function funTwo()

  Dim rsTwo

  Set rsTwo = funOne("SELECT .....")

  funTwo = rsTwo(1)

  rsTwo.Close
  Set rsTwo = Nothing

end function
Can anyone see anything wrong with this? If someone has passed a RS object from on function to another I would be very pleased if you would share the code.

Thanks
dog
  #2 (permalink)  
Old September 21st, 2004, 11:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I have a feeling that the problem is that the recordset is closed. Try making rsone global.

Brian
  #3 (permalink)  
Old September 22nd, 2004, 02:39 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi,
   I feel the same. Just use the following code . Here I just commented last but one line in the first function(rsOne.Close)
It will work

function funOne(sql)

  Dim rsOne

  Set rsOne = Server.CreateObject("ADODB.RecordSet")
  rsOne.Open sql, oConn

  Set funOne = rsOne

  'rsOne.Close
  Set rsOne = Nothing

end function

Thank You
Suresh




  #4 (permalink)  
Old September 22nd, 2004, 03:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't think the last 2 lines in that function are required. Also SET keyword is not required there. But you got to use SET at the location where you call this function.

...
  Set funOne = rsOne

  'rsOne.Close
  Set rsOne = Nothing
...

As you set a value to the FUNCTION name, there by the control goes out of that function to where it is being called. So there shouldn't be any chance of executing the last 2 lines given above.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i return a recordset in a Stored procedure chiefouko VB Databases Basics 6 December 12th, 2006 03:34 AM
function return 'Nothing' problem srinuRocks ASP.NET 2.0 Basics 0 March 10th, 2005 10:32 AM
How to return array value from a function nebpro BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 29th, 2004 12:14 PM
Return a UDT from a function alex_read Pro VB 6 1 April 23rd, 2004 05:37 AM
Can i return a recordset in a Stored procedure chiefouko SQL Server 2000 1 June 23rd, 2003 06:13 AM





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