Retrieving a field from a SQL procedure

Reply

Join Date: Jul 2004
Posts: 1
Reputation: Matt12511 is an unknown quantity at this point 
Solved Threads: 0
Matt12511 Matt12511 is offline Offline
Newbie Poster

Retrieving a field from a SQL procedure

 
0
  #1
Jul 29th, 2004
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:

  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:

  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:

  1. idBasket = rsBasket("idBasket")
And that is where the error comes in.

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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 167
Reputation: Drew is an unknown quantity at this point 
Solved Threads: 7
Drew's Avatar
Drew Drew is offline Offline
Junior Poster

Re: Retrieving a field from a SQL procedure

 
0
  #2
Jul 31st, 2004
Try this:

  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
Drew Gauderman
ASP / MSSQL Coder
http://www.iportalx.net - My ASP Portal
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC