Command Samples
<< Click to Display Table of Contents >> Command Samples |
![]() ![]() ![]() |
The command samples can be found in the <Vo2AdoDir>\Samples\Command
All command examples assume you have a SQL Server available
These samples show:
1. | A Simple command object |
2. | How to call a Stored Procedure with 2 in-parameters and a result set |
3. | How to call a Stored Procedure with output parameters |
4. | How to define parameter objects in your application |
5. | How to handle multiple result sets |
All the samples use the following method to connect to the server (the only difference is that some use the pubs database where others use the Northwind database
FUNCTION OpenConnection AS AdoConnection
LOCAL sError AS STRING
LOCAL oConn AS AdoConnection
LOCAL uError AS USUAL
LOCAL cbErr AS CODEBLOCK
cbErr := ErrorBlock({|oErr|_Break(oErr)})
BEGIN SEQUENCE
oConn := AdoConnection{}
oConn:ConnectionTimeout := 5
// oConn:CursorLocation := AdUseClient
oConn:ConnectionString := "Provider=sqloledb;Data Source=(local);" +;
"Initial Catalog=Pubs;User Id=sa;Password=;"
RECOVER USING uError
? "Error: "+uError:description
quit
wait
END
BEGIN SEQUENCE
oConn:Open(NIL,NIL,NIL<text style="font-family:'Courier New'; font-size:10pt; color:#000064;" translate="true">,NIL)
RECOVER USING uError
END
IF oConn:State <> adStateOpen
// Error occurred
IF oConn:Errors:Count > 0
// Ado Error
sError := oConn:Errors:[Item,0]:Description
ELSEIF IsInstanceOfUsual(uError, #Error)
sError := uError:Description
ELSE
sError := "Unknown error"
END IF
? "Error when making connection: ", sError
wait
quit
ENDIF
ErrorBlock(cbErr)
RETURN oConn