ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<%
' Selected constants from adovbs.inc
Const adCmdStoredProc    = 4
Const adInteger          = 3
Const adParamInput       = 1
' For more info see:
' http://www.asp101.com/articles/john/adovbs/default.asp
' Declare our vars
Dim cnnStoredQuery ' Connection object
Dim cmdStoredQuery ' Command object
Dim rstStoredQuery ' Recordset object
Dim paramId        ' Parameter object
' Establish connection to database (DB)
Set cnnStoredQuery = Server.CreateObject("ADODB.Connection")
cnnStoredQuery.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
	& Server.MapPath("storedqueries.mdb") _
	& ";User ID=admin;"
' Create Command object we'll use to execute the query
Set cmdStoredQuery = Server.CreateObject("ADODB.Command")
' Set our Command to use our existing connection
cmdStoredQuery.ActiveConnection = cnnStoredQuery
' Message so people know what the sample's doing:
Response.Write "<p>Running the stored procedure: " _
	& "<strong>GetNameInfoById</strong>.</p>" & vbCrLf
' Set the SP's name and tell the Command object
' that the name we give is supposed to be a SP
cmdStoredQuery.CommandText = "GetNameInfoById"
cmdStoredQuery.CommandType = adCmdStoredProc
' Message so people know what the sample's doing:
Response.Write "<p>Passing it one parameter:<br />" & vbCrLf _
	& "<strong>Id</strong> = 1<br />" & vbCrLf _
	& "</p>" & vbCrLf
' Create and add the SP's required parameter to our
' Command object.
Set paramId = cmdStoredQuery.CreateParameter("Id", adInteger, adParamInput)
paramId.Value = 1
cmdStoredQuery.Parameters.Append paramId
' Run the SP by executing the command and grab
' the retruned recordset.
Set rstStoredQuery = cmdStoredQuery.Execute
' Message so people know what the sample's doing:
Response.Write "<p>It returned a recordset which I used " _
	& "to print out this name: <strong>"
' Spit out our data which I pull out of the recordset.
Response.Write Trim(rstStoredQuery.Fields("first_name"))
Response.Write " "
Response.Write Trim(rstStoredQuery.Fields("last_name"))
' Message so people know what the sample's doing:
Response.Write "</strong>.</p>" & vbCrLf
' Kill our objects
Set paramId = Nothing
Set rstStoredQuery = Nothing
Set cmdStoredQuery = Nothing
' Close and kill our connection
cnnStoredQuery.Close
Set cnnStoredQuery = Nothing
%>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers