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

newbie question on Command Object

Status
Not open for further replies.

terror

Programmer
Aug 22, 2001
86
US
Hi,
I'm learning login stuff and I'm going thru 4guysfromrolla.com among various other sites. Because I'm new at this, practically everything I read leads to a need to read something else and I'm getting lost.
Can someone explain in layman's terms, the use of the Command object. My book says "it provides much greater flexibility and functionality than executing commands thru the Connection object and increases performance by avoiding continual referral to default values"
call me dense, but this means nothing to me. I barely understand what I'm coding as it is. So, once again, can someone spare a moment for a dense newbie? maybe an example or something?
too much to learn, not enuf hours in the day.
thanks again,
Terror
 
I use the command object to facilitate the use of stored procedures in SQL Server. It has other uses, as well, but I don't use them. So here's an example of how I might use a command object to execute a stored procedure called 'spMe' which expects parameters, val1 and val2, and returns to me a variable, output:

dim comObj, con
set con = server.createObject ("ADODB.Connection")
set comObj = server.createObject ("ADODB.Command")

'open the connection
con.open "DSN=myDSN"

'set the values for the command object
comObj.activeConnection = con
comObj.commandText = "spMe"
comObj.commandType = 4 'adCmdStoredProcedure

'assign the values to the command object to prepare
' for execution
comObj.parameters("@val1") = someVariable
comObj.parameters("@val2") = someOtherVariable

'execute my stored procedure
comObj.execute

'retrieve my output variable, and place into a local one
dim theOutput
theOutput = comObj.parameters("@output")

'take out the trash
set comObj = nothing
set con = nothing

Using a command object in this fashion allows you to take advantage of the greatest thing to ever happen to a database: a stored procedure

Stored procedures make your code run faster for many reasons, not the least of which is the fact that the more pieces you break your code into (abstraction), the more manageable it becomes, and the more tiers you can spread the processing across. It will also make your code much more readable and easy to follow.

Oh yeah, and it would make your programming teacher/mentor very proud for sticking to OO type principles.

Well, that's my stab at a pseudo-explanation. ;-)

hope it helps you out.
Paul Prewett
penny.gif
penny.gif
 
Paul, so command object makes it more modular?
thanks for the info. My hosting service does not support SQL Server. I am also working with a dsn-less connection.
I'm using Access 2000 and I don't see anything in help about stored procedures so I assume I can't use them with access unless someone tells me differently. I am my own teacher so I guess I'll yell at myself about OOP.
thanks for your time.
cheers,
-Terror
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top