CursorRefresh Method
Refreshes a cursor with current data from the data source. CursorRefresh re-executes the value of the SelectCmd parameter in the BeforeCursorRefresh event with respect to CursorAdapterDataSourceType.
Note If the SelectCmd parameter in the BeforeCursorRefresh event contains parameters, you can modify the scope of the rows that are returned through the original query by changing the parameters.
CursorAdapter.CursorRefresh()
Return Values
Logical data type. CursorRefresh returns True (.T.) if the cursor is repopulated successfully and False (.F.) if not repopulated successfully.
Remarks
CursorRefresh updates the following properties for the ADO or ODBC-based cursor from the following CursorAdapter properties:
- AllowSimultaneousFetch
- CompareMemo
- FetchAsNeeded
- FetchMemo
- FetchSize
- MaxRecords
- Prepared
- UseMemoSize
Visual FoxPro generates an error message when the cursor contains unsaved changes.
If the CursorAdapterDataSourceType property is "ADO" when executing the CursorAdapterCursorFill method, CursorRefresh behaves in the following manner:
- CursorAdapter objecct has an attached cursor resulting from executing SelectCmd using CursorFill:
- Sets the ADO Command CommandText property for the ADO RecordSet ActiveCommand object to the SelectCmd used to open the ADO RecordSet unless CommandText already contains this value.
- Refreshes the Command object parameters collection and re-evaluates the parameter values.
- Calls the ADO RecordSet Requery method and passes the same values in the nOptions parameter used by CursorFill to open the ADO RecordSet.
- CursorAdapter object has an attached cursor resulting from passing an already open ADO RecordSet to the CursorFillSource parameter.
- Calls the ADO RecordSet Requery method and pass the same value for the nOptions parameter used by CursorFill.
Example
Example 1
The following example illustrates retrieving results using ADO with a parameter and using CursorRefresh to refresh data. The connection string settings for SQL Server (localhost) and Visual FoxPro OLE DB Provider are the following:
* .ConnectionString = 'provider=SQLOLEDB.1;data source=localhost;'+
* 'initial catalog=Northwind;trusted_connection=yes'
CLEAR
LOCAL loConn AS ADODB.CONNECTION, ;
loCommand AS ADODB.COMMAND, ;
loException AS EXCEPTION, ;
loCursor AS CURSORADAPTER, ;
country, ;
laErrors[1]
loConn = CREATEOBJECT('ADODB.Connection')
WITH loConn
.ConnectionString = 'provider=vfpoledb;data source=' + ;
HOME(2)+'northwind\Northwind.dbc'
TRY
.OPEN()
CATCH TO loException
MESSAGEBOX(loException.MESSAGE)
CANCEL
ENDTRY
ENDWITH
loCommand = CREATEOBJECT('ADODB.Command')
loCommand.ActiveConnection = loConn
loCursor = CREATEOBJECT('CursorAdapter')
WITH loCursor
.ALIAS = 'Customers'
.DATASOURCETYPE = 'ADO'
.SELECTCMD = ;
'select * from customers where country=?lcCountry'
lcCountry = 'Brazil'
.DATASOURCE = CREATEOBJECT('ADODB.Recordset')
.DATASOURCE.ActiveConnection = loConn
llReturn = .CURSORFILL(.F., .F., 0, loCommand)
IF llReturn
BROWSE
lcCountry = 'Canada'
llReturn = .CURSORREFRESH()
IF llReturn
BROWSE
ENDIF llReturn
ELSE
AERROR(laErrors)
MESSAGEBOX(laErrors[2])
ENDIF llReturn
ENDWITH
The following example that illustrates using CursorRefresh with an already opened ADO Recordset. The connection string settings for SQL Server (localhost) and the Visual FoxPro OLE DB Provider are:
* .ConnectionString = 'provider=SQLOLEDB.1;data source=localhost;' + ;
* 'initial catalog=Northwind;trusted_connection=yes'
CLEAR
LOCAL loConn AS ADODB.CONNECTION, ;
loCommand AS ADODB.COMMAND, ;
loParam AS ADODB.PARAMETER, ;
loRs AS ADODB.Recordset,;
loException AS EXCEPTION, ;
loCursor AS CURSORADAPTER, ;
lcCountry, ;
laErrors[1]
loConn = CREATEOBJECT('ADODB.Connection')
WITH loConn
.ConnectionString = 'provider=vfpoledb;data source=' + ;
HOME(2)+'northwind\Northwind.dbc'
TRY
.OPEN()
CATCH TO loException
MESSAGEBOX(loException.MESSAGE)
CANCEL
ENDTRY
ENDWITH
loCommand = CREATEOBJECT('ADODB.Command')
loCommand.CommandText = ;
"SELECT * FROM customers WHERE Country = ?"
loParam = loCommand.CreateParameter("Country", 129, 1, 15, "")
loCommand.PARAMETERS.APPEND(loParam)
loCommand.PARAMETERS("Country") = "Brazil"
loCommand.ActiveConnection = loConn
loRs = loCommand.Execute()
loCursor = CREATEOBJECT('CursorAdapter')
WITH loCursor
.ALIAS = 'Customers'
.DATASOURCETYPE = 'ADO'
llReturn = .CURSORFILL(.F., .F., 0, loRs)
IF llReturn
BROWSE
loRs.ActiveCommand.PARAMETERS("Country") = "Canada"
llReturn = .CURSORREFRESH()
IF llReturn
BROWSE
ENDIF llReturn
ELSE
AERROR(laErrors)
MESSAGEBOX(laErrors[2])
ENDIF llReturn
ENDWITH
See Also
Methods | CursorAdapter Object Properties, Methods, and Events | BeforeCursorRefresh Event
Applies To: CursorAdapter Class