The Command Object - Output Parameters Without Closing Recordsets
(Page 8 of 8 )
There are two solutions to the problem of parameters not being available until the recordset is closed. The first is simply a matter of using client-side cursors, which allows the parameters to be immediately available.
The second method involves the naming of stored procedures by using the Command object's Name property. You've already seen that code similar to this is allowed:
strConn = "Provider=SQLOLEDB; Data Source=SQL7Server; " & _
"Initial Catalog=TestData; User Id=sa; Password="
objConn.Open strConn
objCmd.CommandText = "usp_AStoredProcedure"
objCmd.CommandType = adCmdStoredProc
Set objParam = objCmd.CreateParameter("ID", adInteger,
adParamInput, 8, 123)
objCmd.Parameters.Append objParam
Set objParam = _
objCmd.CreateParameter("Name", adVarChar, _
adParamInput, 25, "Janine")
objCmd.Parameters.Append objParam
objCmd.Name = "StoredProcedureName"
Set objCmd.ActiveConnection = objConn
objConn.StoredProcedureName
This was never well documented, but what's even less well documented is that you can pass the arguments to the stored procedure and a recordset object like so:
objConn.StoredProcedureName Argument1, Argument2, objRec
The arguments are accepted by the stored procedure in the normal way, and the recordset object is filled accordingly. As soon as this command is executed, you can access the return and output parameters even though the recordset is still open.
As a word of warning, you shouldn't really rely on this procedure; because it's not documented, there's no way of telling whether this will continue to work in future versions of ADO.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from ADO Programmer's Reference by David Sussman (Apress, 2004; ISBN: 1590593421). Check it out at your favorite bookstore. Buy this book now.
|
|