Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: HOW TO PASS PARAMETERS TO A STORED PROCEDURE USING ASP


Message #1 by "KASI VISWANATHAN" <Kasvi@r...> on Sat, 24 Mar 2001 19:25:52
HI 



I AM DEVELOPING AN ECOMMERCE SITE FOR ONLINE CD STORE. I HAVE TWO ASP 

PAGES TO START WITH ONE IS DEPT AND OTHER IS PRODUCT. I HAVE TO PASS A 

PARAMETER FROM DEPT TO PRODUCT (I.E. DEPTID) AND USING THAT PARAMETER I 

HAVE TO RETRIEVE A RECORDSET USING ADO.



I HAVE BEEN EXPERIENCING PROBLEMS TO PASS MULTIPLE PARAMETERS AND ALSO 

USING A HREF TAG TO PASS VALUES TO URL.



MY RESULT SHOULD BE DYNAMIC I.E. SELECT DEPARTMENT - > PASS DEPT ID

DISPLAY PRODUCTS PERTAINING TO DEPT.



I GET A SINGLE RESULTSET ALL THE TIME WHEN I EXECUTE IT. I NEED TO KNOW 

WHETHER MY SYNTAX IS CORRECT OR NOT. IS THERE ANY WAY I CAN ACHIEVE THIS 

BY USING STORED PROCEDURES. COULD YOU SEND ME A CORRECT SYNTAX OF SOLVING 

THIS - PASSING PARAMETER TO STORED PROCEDURE USING ASP



MY CODE -->



<%@ Language=VBScript %>

<!-- #include file="adovbs.inc" -->

<!-- #include file="header.asp" -->

<HTML>

<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">

</HEAD>

<BODY>





<!-- Products.asp - This page displays the products in a department -->

-->



<%



 ' Create an ADO connection

  Set objconn = server.createobject("ADODB.connection")

  set objcmd = server.createobject("ADODB.Command")

 'Create an recordset

 set rsdepartment = server.createobject("ADODB.recordset")

 'open the connection using 

 objconn.open "Provider=SQLOLEDB.1;Persist Security Info=False;User 

ID=sa;Initial Catalog=pubs"

    

    If objConn.State = adStateOpen Then

  

 str = "select * from department"

 set rsdepartment = objconn.execute(str)

  'response.write rsdepartment

 

    Set objCmd.ActiveConnection = objconn

objCmd.CommandText = "sp_retrievedept"

    objCmd.CommandType = adCmdStoredProc

     

  

  objCmd.Parameters.Append objcmd.CreateParameter("iddepartment", _ 

    adInteger,adParaminput)  

  int a 

  

 a = Request.QueryString("iddepartment")

 do until rsdepartment.EOF  

 if    objcmd.Parameters("iddepartment").Value = a then

set rsdepartment = objcmd.Execute

 objcmd.parameters.refresh 

 else

  end if

  loop

   

 'rsdepartment.Requery(adasyncexecute)

 'intparamavail = objconn.Properties(" In Parameter Availability")

   'If parameter not available until recordset is closed then

  'if intparamavail = 3   then

  'rsdepartment.Close 

  'end if

  'strinparam = objcmd.Parameters("input_param")

  

Response.Write(request.querystring("iddepartment"))

Response.Write(Request.querystring("chrdeptname"))

Response.Write(Request.QueryString("chrdeptimage"))



txtdescription = rsdepartment("txtdeptdesc")

txtdeptname = rsdepartment("chrdeptname")

chrdeptimage = rsdepartment("chrdeptimage")



' Store the ID of the department being referenced in

' the lastiddept session variable. This will allow us

' to build a link to the basket back to the department

' for further shopping.



session("Lastiddept") = request("iddepartment")

 

  

else

   

    For Each objErr In objConn.Errors

        Debug.Print objErr.Description

    Next



    

  ' End If

'   Set objCmd = Nothing

 '  objConn.Close

  'Set objConn = Nothing





'Retrieve the product information





Response.Write  iddepartment



'



  

  

  

  end if

  





 'Display all errors



 

 %>  

 

 <CENTER>

 <Img src="HLPCD.GIF"<%=chrdeptimage%>" align="middle">

 <%=txtdeptname%><FONT SIZE="4"><B></b></font><BR><BR>

</CENTER>

<!-- Display the description -->

 <%=txtdescription%> Select a product :<BR><BR>

 <% 

 

 'create an ADODB connection

  set dbproducts = server.createobject("ADODB.Connection")

 'create an record set

set obcmd = server.createobject("ADODB.Command")

  set rsproducts = server.createobject("ADODB.recordset")

'Open the connection 

dbproducts.open "Provider=SQLOLEDB.1;Persist Security Info=False;User 

ID=sa;Initial Catalog=pubs"



str ="Select * from products"

set rsproducts=dbproducts.Execute(str)



    Set obCmd.ActiveConnection = objconn

obCmd.CommandText = "sp_retrievedeptproducts"

    obCmd.CommandType = adCmdStoredProc

     

  

  obCmd.Parameters.Append obcmd.CreateParameter("iddept", _ 

    adInteger,adParaminput,0)  

 obcmd.Parameters("iddept").Value = 1

 obcmd.Parameters("iddept").Value = 2

 obcmd.Parameters("iddept").Value = 3

   set rsproducts = obcmd.Execute

 obcmd.parameters.refresh 

  'intparamavail = objconn.Properties(" In Parameter Availability")

  ' If parameter not available until recordset is closed

  if intparamavail = 1 then

  rsproducts.Close 

  end if





' We are going to rotate the images from left to right

Flag = 0

 

 'Loop through the products recorset

 do until rsproducts.EOF

 

 'Retrieve the product info to be displayed

 chrproductname  = rsproducts("chrproductname")

 chrproductimage = rsproducts("chrproductimage")

 idproduct = rsproducts("idproduct")

 

 ' Check the display flag. We will rotate the product

  'images from left to right

   

   If flag = 0 then

  '  set the flag

   flag = 1

   %>

  

  <!-- Build the link to the product information -->

  <a href="product.asp?idproduct=<%=idproduct%>">

  <img src="images/products/sm_<%=chrproductimage%>"

  <%=chrproductname%></a><BR><BR>



  <% else %>



  <!-- Build the link to the product information -->

  <a href="product.asp?idproduct=<%=idproduct%>">

  <%=chrproductname%>

  <img src="hot.gif"/products/sm_<%=chrproductimage%>"

  align="middle" border="0"></a><BR><BR>



  <%

  

  

  'Reset the flag

  flag = 0



end if    

  

  'move to the next row

  rsproducts.movenext

  

  loop

  

  'end if

  

  %>





  

  <!-- #include file="footer.asp" -->



</BODY>

</HTML>





-->>




  Return to Index