KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Binding and retrieving resultset to fields
PRODUCT: 4D ODBC | VERSION: 2004.4 | PLATFORM: Mac & Win
Published On: July 7, 2006
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

The code below shows how to bind columns of the resultset of a query to 4D fields and how to fetch results using 4D ODBC Pro commands:

C_TEXT($tSQL)

$tSQL:="SELECT CompanyID,Type,Functions,Company_Name FROM Company"

$iResult:=ODBC_SQLAllocConnect ($iConnID)

$iResult:=ODBC_SQLConnect ($iConnID;$tDataSource;$tUName;$tPswd)

$iResult:=ODBC_SQLAllocStmt ($iConnID;$iStmtID)

$iResult:=ODBC_SQLPrepare ($iStmtID;$tSQL)

$iResult:=ODBC_SQLExecute ($iStmtID)

$iResult:=ODBC_SQLBindCol ($iStmtID;1;->[Company]CompanyID)

$iResult:=ODBC_SQLBindCol ($iStmtID;2;->[Company]Type)

$iResult:=ODBC_SQLBindCol ($iStmtID;3;->[Company]Functions)

$iResult:=ODBC_SQLBindCol ($iStmtID;4;->[Company]Company_Name)

While (($iResult#SQL_NO_DATA ) & ($iResult#SQL_ERROR ))

     CREATE RECORD([Company])

     $iResult:=ODBC_SQLFetch ($iStmtID)

     If (($iResult#SQL_NO_DATA ) & ($iResult#SQL_ERROR ))

          SAVE RECORD([Company])

     End if

End while