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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Object

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
Suppose I am retrieving records from SQL Server using a stored procedure named PaySlip. Now if I am using the RECORDSET object, I can display all the records in a web page by using

<%
Do Until(objRS.EOF)
Response.Write(objRS(&quot;FieldName1&quot;))
Response.Write(objRS(&quot;FieldName2&quot;))
Response.Write(objRS(&quot;FieldName3&quot;))
objRS.MoveNext
Loop
%>

But how do I display the records if I am using the COMMAND object? For eg. if I have the following ASP code:

<%
Dim objCmd
Set objCmd=Server.CreateObject(&quot;ADODB.COMMAND&quot;)
objCmd.ActiveConnection=objConn
objCmd.CommandText=&quot;PaySlip&quot;
objCmd.CommandType=adCmdStoredProc
objCmd.Parameters.Append objCmd.CreateParameter(&quot;@ccode&quot;,200,1,5,strCCode)
objCmd.Parameters.Append objCmd.CreateParameter(&quot;@month&quot;,3,1,5,arrPeriod(0))
objCmd.Parameters.Append objCmd.CreateParameter(&quot;@year&quot;,3,1,5,arrPeriod(1))
objCmd.Execute()
%>

Also when should the RECORDSET object be used & when should the COMMAND object be used if a stored procedure is used? Are there any advantages/disadvantages of using one over the other?

Thanks,

Arpan
 
Looks good... This is the best way (using a SP to load a recordset)

Code:
Dim objCmd
Set objCmd=Server.CreateObject(&quot;ADODB.COMMAND&quot;)
objCmd.ActiveConnection=objConn
objCmd.CommandText=&quot;PaySlip&quot;
objCmd.CommandType=adCmdStoredProc
objCmd.Parameters.Append objCmd.CreateParameter(&quot;@ccode&quot;,200,1,5,strCCode)
objCmd.Parameters.Append objCmd.CreateParameter(&quot;@month&quot;,3,1,5,arrPeriod(0))
objCmd.Parameters.Append objCmd.CreateParameter(&quot;@year&quot;,3,1,5,arrPeriod(1))
SET objRS = objCmd.Execute()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top