Navigation:  Samples >

Parameters sample

Previous pageReturn to chapter overviewNext page

This example sets two query parameters for a hypothetical parameter query named "ParamQuery," executes the query by opening a Recordset from the QueryDef, and then prints the properties of each parameter. Note that this query does not actually exist in the Northwind sample database. The parameter data types are of type Date. See the methods and properties listed in the Parameter summary topic for additional examples.

 

FUNCTION Start

LOCAL oDbEng        AS DaodBEngine

LOCAL oDb        AS DaoDatabase

LOCAL oQd        AS DaoQueryDef

LOCAL oPar        AS DaoParameter

LOCAL oRst        AS DaoRecordSet

LOCAL i        AS LONG

BEGIN SEQUENCE

 set color TO w+/B

 cls

 

 oDbEng  := DaoDbEngine{}

 oDb        := oDbEng:OpenDatabase("\VO2Jet\Northwind.mdb",NIL,NIL,NIL)

 oQd                := oDb:QueryDefs:[Item,"Sales by year"]

 ? "Query ",oQd:name," has ",oQd:Parameters_:Count,"PARAMETERS"

 ? "#,Name, type, direction"

 FOR i := 1 TO oQd:Parameters_:Count

         oPar        := oQd:Parameters_:[Item,i]

         ? i, oPar:name, ;

                 DaoDataType(oPar:Type), ;

                 DaoEnum2Str(oPar:Direction,DaoParameterDirectionEnum(),FALSE)

 NEXT

 // Set date range for this query

 ? "Sales for August 1994"

 oQd:Parameters_:[Item,1]:value := 1994.08.01

 oQd:Parameters_:[Item,2]:value := 1994.08.31

 oRst := oQd:OpenRecordSet(NIL,NIL,NIL)

 DO WHILE ! oRst:Eof

         ? oRst:[Collect, "orderId"], oRst:[Collect, "ShippedDate"]:DateVal

         oRst:MoveNext()

 ENDDO

 wait

 // Set date range for this query

 ? "Sales for September 1994"

 oQd:Parameters_:[Item,1]:value := 1994.09.01

 oQd:Parameters_:[Item,2]:value := 1994.09.30

 oRst := oQd:OpenRecordSet(NIL,NIL,NIL)

 DO WHILE ! oRst:Eof

         ? oRst:[Collect, "orderId"], oRst:[Collect, "ShippedDate"]:DateVal

         oRst:MoveNext()

 ENDDO

 

END

Wait