DbGetFieldString

ODBC function.

The DbGetFieldString function retrieves the contents of any non-numeric field within the current record for the dataset in use. Not available in WinTask Lite.

Syntax

DbGetFieldString(<field_name>,<string>)
or
Ret=DbGetFieldString(<field_name>,<string>)

Parameters

<field_name>, string, name of the field to retrieve.

<string>, string, a variable which will contain the contents of the field.

Return value

Ret, numeric return code. If the retrieval has been done, the function returns 0, otherwise use this return code for error management.

Example

 

DbConnect("DSN=gpao;PWD=SILOG") ' connection to ODBC database called gpao

DbSelect("SELECT * FROM Business",DYNASET) ' select all records in table Business.

#IgnoreErrors=0 ' error management inside the script.

While not DbEof() ' while there are still records to read.

Err=DbGetFieldString("Value",val$) ' val$ will be set to the contents of the

' Value field (it is returned as a string).

If err<>0 then ' if an error occurs during retrieval.

Goto gesterr ' call an error routine.

endif

msgbox(val$) ' display the extracted field.

DbMovenext() ' move to next record.

Wend

Example code

'Declare first in system configuration, ODBC databases, your target ODBC database

'in this script, we have called it DBASE

 

sub display_enreg()

'It displays in one long string the retrieved fields.

mes$="ID : "+str$(id)

mes$=mes$+"\n\"+"SiteCode : "+sitecode$

mes$=mes$+"\n\"+"RequestNumber : "+requestnumber$

mes$=mes$+"\n\"+"Notes : "+notes$

mes$=mes$+"\n\"+"Address : "+address$

mes$=mes$+"\n\"+"City : "+city$

mes$=mes$+"\n\"+"State : "+state$

mes$=mes$+"\n\"+"Zip : "+zip$

 

msgbox(mes$,64,"Record "+str$(i+1))&#9;&#9;

 

endsub

'------------------------------------------

sub extract()

nbenreg=DbRecordCount() 'get total records

if nbenreg > 0 then

msgbox(str$(nbenreg)+ " records(s) to process")

DbMoveFirst()

i=0

repeat

DbGetFieldNumeric("ID",id)

DbGetFieldString("SiteCode",sitecode$)

DbGetFieldString("RequestNumber",requestnumber$)

DbGetFieldString("Notes",notes$)

DbGetFieldString("Address",address$)

DbGetFieldString("City",city$)

DbGetFieldString("State",state$)

DbGetFieldString("Zip",zip$)

display_enreg()

DbMoveNext()

i=i+1

until i=nbenreg

else

msgbox("No record to process")

endif

endsub

'************************************

 

res=dbconnect("DSN=DBASE")

res=dbselect("SELECT * FROM Table1",DYNASET)

extract()