ADO Command and Stored Procedures


You can design stored procedures to hide such complexities, leaving a more concise interface available for application development.

The command object has the power to change the query each time it is used. The code below demonstrates how to use the ADO command object with these stored procedure. First, create the command object and connect the connection object to the command object.

'create a command object
set cm = Server.CreateObject("ADODB.Command")
'connect the command
cm.ActiveConnection = cn

Next, specify the query.

Method 1

set cm.CommandText = "Select * from schools"

Method 2 (Table)

set cm.CommandText = "schools"
cm.CommandType = adCmdTable

Method 3 (Stored Procedure)

set cm.CommandText = "add_school"
cmdCommandType = adCmdStoredProc

Method 4 (Stored Procedure with Parameters)

set cm.CommandText = "add_school"
cm.cmdCommandType = adCmdStoredProc

set p = cm.Parameters

p.Append cm.CreateParameter("@style",adChar,adParamInput,50)
p.Append cm.CreateParameter("@school", adChar, adParamInput,50)
p.Append cm.CreateParameter("@id",adInteger,adParamInput)

cm("@style") = "Kempo"
cm("@school") = "WSU"
cm(Id) = 1


Method 5 ( Return the results to a recordset)

rs.Open cm, cn

Method 6 ( Recordset, type, and locking method)

rs.Open cm, cn, adOpenKeyset, adLockOptimistic

You might also like...


David Nishimoto NishiSoft provides Part I of the Information Technology Project collaboration. Sign up and list your IT project tasks, assign task too friends, and get percent complete task. Part will include a wo...


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius