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 CursorAdapter DataSourceType.
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 Value
Logical data type. CursorRefresh returns True (.T.) if the cursor is repopulated successfully and False (.F.) if not repopulated successfully.
Note |
---|
To retrieve error information when CursorRefresh returns False (.F.), you must call the AERROR( ) function because Visual Foxpro error handling, such as the ON ERROR command, Error event, and TRY...CATCH...FINALLY command, does not capture this error information.
|
Remarks
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:
| Copy Code |
---|
* .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:
| Copy Code |
---|
* .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