943,653 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 6121
  • ASP RSS
Jul 29th, 2004
0

Retrieving a field from a SQL procedure

Expand Post »
Hello all,

I have been working out of an older ASP/Visual Basic/SQL Server Developers Guide. My code is exactly as written in the book but I still can't seem to get the asp to collect the information from the Stored Procedure.

My asp page calls for the Procedure:

ASP Syntax (Toggle Plain Text)
  1.  
  2. 'check to see if a basket has been created
  3. if session("idBasket") = "" then
  4. set dbBasket = server.CreateObject("adodb.connection")
  5. set rsBasket = server.CreateObject("adodb.recordset")
  6. dbBasket.open "Provider=sqloledb;Data Source=(local);Initial Catalog=EcommerceDB;User Id=sa;Password=12511;"
  7.  
  8. sql = "execute sp_CreateBasket " & session("idShopper")
  9.  
  10. set rsBasket = dbBasket.Execute(sql)
The Stored Procedure is this simple:

ASP Syntax (Toggle Plain Text)
  1. Create Procedure sp_CreateBasket
  2. @idShopper int
  3. AS
  4. Insert into basket(idShopper) values(@idShopper)
  5. Select idBasket = @@identity
Then I call the information from my asp like this:

ASP Syntax (Toggle Plain Text)
  1. idBasket = rsBasket("idBasket")
And that is where the error comes in.

Quote ...
Item cannot be found in the collection corresponding to the requested name or ordinal.
I have tested the Procedure in SQL Analyzer and it returns idBasket with the correct number.

Any ideas?

Thanks,

Matt
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Matt12511 is offline Offline
1 posts
since Jul 2004
Jul 31st, 2004
0

Re: Retrieving a field from a SQL procedure

Try this:

ASP Syntax (Toggle Plain Text)
  1. if session("idBasket") = "" then
  2. 'Open DB
  3. set dbBasket = server.CreateObject("adodb.connection")
  4. dbBasket.open "Provider=sqloledb;Data Source=(local);Initial Catalog=EcommerceDB;User Id=sa;Password=12511;"
  5. set rsBasket = server.CreateObject("adodb.recordset")
  6.  
  7. sql = "execute sp_CreateBasket idShopper=" & session("idShopper")
  8.  
  9. rsBasket.Open sql, dbBasket
  10. idBasket = rsBasket("idBasket")
  11.  
  12. 'Always close connections or server will suffer
  13. rsBasket.Close
  14. Set rsBasket = Nothing
  15.  
  16. 'Close main connection
  17. dbBasket.Close
  18. set dbBasket = Nothing
  19. End If
Reputation Points: 25
Solved Threads: 7
Junior Poster
Drew is offline Offline
166 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Search by Zip Radius
Next Thread in ASP Forum Timeline: getting email adress from logon_user





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC