Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO ACCESS STORED PROCEDURES THROUGH ASP

Status
Not open for further replies.

Kasvi

Programmer
Mar 20, 2001
1
MO
WELL I GOT A DEPARTMENT AND PRODUCT PAGE. I NEED TO PASS DEPTID AS A PARAMETER VALUE TO A STORE PROCEDURE AND RETRIEVE THE DEPARTMENTS. wITH THAT PARAMETER VALUE I NEED TO GET THE RELEVANT PRODUCTS FROM A TABLE CALLED DEPTPRODUCTS.

I AM ABLE TO PASS VALUES ONE BY ONE AS A PARAMETER. IS THERE ANY WAYS TO ACCOMPLISH THIS TASK EASIER. KINDLY PROVIDE THE CODE FOR THAT ?

HERE IS MY CODE.

THANKS AND REGDS
KASI VISWANATHAN



---->>

<%@ Language=VBScript %>
<!-- #include file=&quot;adovbs.inc&quot; -->
<!-- #include file=&quot;header.asp&quot; -->
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>


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

<%

' Create an ADO connection
Set objconn = server.createobject(&quot;ADODB.connection&quot;)
set objcmd = server.createobject(&quot;ADODB.Command&quot;)
'Create an recordset
set rsdepartment = server.createobject(&quot;ADODB.recordset&quot;)
'open the connection using
objconn.open &quot;Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs&quot;
If objConn.State = adStateOpen Then

str = &quot;select * from department&quot;
set rsdepartment = objconn.execute(str)
'response.write rsdepartment

Set objCmd.ActiveConnection = objconn
objCmd.CommandText = &quot;sp_retrievedept&quot;
objCmd.CommandType = adCmdStoredProc


objCmd.Parameters.Append objcmd.CreateParameter(&quot;iddepartment&quot;, _
adInteger,adParaminput)
objcmd.Parameters(&quot;iddepartment&quot;).Value = 2
set rsdepartment = objcmd.Execute
objcmd.parameters.refresh
'rsdepartment.Requery(adasyncexecute)
'intparamavail = objconn.Properties(&quot; In Parameter Availability&quot;)
' If parameter not available until recordset is closed
if intparamavail = 2 then
'rsdepartment.Close
end if
'strinparam = objcmd.Parameters(&quot;input_param&quot;)

Response.Write(request.querystring(&quot;iddepartment&quot;))
Response.Write(Request.querystring(&quot;chrdeptname&quot;))
Response.Write(Request.QueryString(&quot;chrdeptimage&quot;))

txtdescription = rsdepartment(&quot;txtdeptdesc&quot;)
txtdeptname = rsdepartment(&quot;chrdeptname&quot;)
chrdeptimage = rsdepartment(&quot;chrdeptimage&quot;)


' 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(&quot;Lastiddept&quot;) = request(&quot;iddepartment&quot;)


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

'



'Display all errors


%>

<CENTER>
<Img src=&quot;HLPCD.GIF&quot;<%=chrdeptimage%>&quot; align=&quot;middle&quot;>
<%=txtdeptname%><FONT SIZE=&quot;4&quot;><B></b></font><BR><BR>
</CENTER>
<!-- Display the description -->
<%=txtdescription%> Select a product :<BR><BR>
<%

'create an ADODB connection
set dbproducts = server.createobject(&quot;ADODB.Connection&quot;)
'create an record set
set obcmd = server.createobject(&quot;ADODB.Command&quot;)
set rsproducts = server.createobject(&quot;ADODB.recordset&quot;)
'Open the connection
dbproducts.open &quot;Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs&quot;

str =&quot;Select * from products&quot;
set rsproducts=dbproducts.Execute(str)

Set obCmd.ActiveConnection = objconn
obCmd.CommandText = &quot;sp_retrievedeptproducts&quot;
obCmd.CommandType = adCmdStoredProc


obCmd.Parameters.Append obcmd.CreateParameter(&quot;iddept&quot;, _
adInteger,adParaminput)
obcmd.Parameters(&quot;iddept&quot;).Value = 1
set rsproducts = obcmd.Execute
obcmd.parameters.refresh
'intparamavail = objconn.Properties(&quot; In Parameter Availability&quot;)
' 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(&quot;chrproductname&quot;)
chrproductimage = rsproducts(&quot;chrproductimage&quot;)
idproduct = rsproducts(&quot;idproduct&quot;)

' 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=&quot;product.asp?idproduct=<%=idproduct%>&quot;>
<img src=&quot;images/products/sm_<%=chrproductimage%>&quot;
<%=chrproductname%></a><BR><BR>

<% else %>

<!-- Build the link to the product information -->
<a href=&quot;product.asp?idproduct=<%=idproduct%>&quot;>
<%=chrproductname%>
<img src=&quot;hot.gif&quot;/products/sm_<%=chrproductimage%>&quot;
align=&quot;middle&quot; border=&quot;0&quot;></a><BR><BR>

<%


'Reset the flag
flag = 0

end if

'move to the next row
rsproducts.movenext

loop

%>



<!-- #include file=&quot;footer.asp&quot; -->

</BODY>
</HTML>


-->>

 
You can execute a stored procedure by using your ADO Connection object...

myCon.execute &quot;EXEC mySPROC '123-45-6789', 0&quot;

and so on, just adding more and more variables separated by commas.

good luck! :)
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top