Navigation:  Samples >

Connection Sample

Previous pageReturn to chapter overviewNext page

This example shows how to start ODBC workspace, connect with a database , open a recordset and process the recordset

 

FUNCTION Start

LOCAL oEng        AS DaodBEngine

LOCAL oWs        AS DaoWorkspace

LOCAL oConn AS DaoConnection

LOCAL oQd        AS DaoQueryDef

LOCAL oRs        AS DaoRecordSet

LOCAL oSrv        AS DaoServer

set color TO w+/B

cls

oEng        := DaoDbEngine{}

// Create ODBC workspace

oWs := oENg:CreateWorkspace("Test","sa","",DbUseOdbc)

oEng:Workspaces:Append(oWs)

// OPen connection to MsSql Server Pubs database (You must setup the Pubs DSN yourself !

oCOnn := oWs:OpenConnection("ODBC;Dsn=Pubs",0,NIL,NIL)

 

? "Connection           name:",oConn:Name

? "Connection connect string:",oConn:Connect

? "Connection Query Timeout :",oConn:QueryTimeOut

? "Connection transactions  :",oConn:Transactions

? "Connection updatable     :",oConn:Updatable

? "Connection Database name :",oConn:Database:Name

 

// Create new querydef

oQd := oConn:CreateQueryDef("titles","Select * from Titles")

? "Connection Querydefs name:", oConn:QueryDefs[1]:Name

? "Connection Querydefs SQL :", oConn:QueryDefs[1]:SQL

// Open recordset

oRs := oQd:OpenRecordSet(DbOpenDynamic,DbExecDirect,DbOptimisticValue)

? "Connection RecordSet name:", oConn:RecordSets[1]:Name

wait

? "Show recordset first 2 columns"

DO WHILE ! oRs:Eof

 ? oRs[1]:Value, oRs[2]:Value

 oRs:MoveNext()

ENDDO

wait

? "No loop using a server"

oSrv := DaoServer{oRs}

oSrv:GoTop()

DO WHILE ! oSrv:Eof

 ? oSrv:FIELDGET(1), oSrv:FIELDGET(2)

 oSrv:Skip(1)

ENDDO

wait