7: Source property
<< Click to Display Table of Contents >> 7: Source property |
![]() ![]() ![]() |
This sample shows you the how you can change the source of a AdoServer
Examples are:
•a new string
•a AdoCommand object with a parameter
•a new value for the AdoCommand parameter
FUNCTION Start()
LOCAL oSrv AS AdoServer
LOCAL oConn AS AdoConnection
LOCAL oCmd AS AdoCommand
LOCAL oPar AS AdoParameter
LOCAL strCnn AS STRING
oConn := AdoConnection{}
oConn:CursorLocation := AdUseServer
strCnn := "Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Vo2Ado26\Northwind.mdb;" +;
";User Id=Admin;Password=;"
oConn:Open(strCnn,NIL,NIL,NIL)
// Open server
oSrv := AdoServer{"Select top 1 * from Employee order by emp_id", oConn,AdOpenStatic}
? "Original Source"
ShowSource(oSrv)
// Change source using String
oSrv:Source := "Select * from Employee where emp_id like 'P%' order by emp_id"
? "New Source"
ShowSource(oSrv)
DO WHILE ! oSrv:EOF
? oSrv:FieldGet(1), oSrv:FieldGet(2)
oSrv:Skip(1)
ENDDO
wait
// Change source using Command
oCmd := AdoCommand{}
oCmd:ActiveConnection := oConn
oCmd:CommandText := "Select * from Employee where emp_id like ?"
oPar := oCmd:CreateParameter("Par1",adVarChar, adParamInput,10,"P%")
oCmd:Parameters_:Append(oPar)
oSrv:Source := oCmd
? "AdoCommand as source"
ShowSource(oSrv)
DO WHILE ! oSrv:EOF
? oSrv:FieldGet(1), oSrv:FieldGet(2)
oSrv:Skip(1)
ENDDO
wait
// Change source using Same Command with different parameter
oCmd:Parameters_:[Item,1]:Value := "A%"
oSrv:Source := oCmd
? "AdoCommand as source with different parameter"
ShowSource(oSrv)
WAIT
FUNCTION ShowSource(oSrv AS AdoServer)
? "Source: ",oSrv:Source
? "Fcount: ",oSrv:Fcount
? "RecCount:",oSrv:RecCount
? "FieldGet:",oSrv:FieldGet(1)