>How to display SDF file (SQLCE) content via VFP CursorAdapter

>VFP 9.0 has a nice tool named DataExplorer… you can launch it from Command Window eg. do home()+"DataExplorer.app".

With DataExplorer youl could access SQL Server Databases+Tables,VFP NativeTables also SQL Server Compact database (.sdf) .

DataExplorer offer you an nice code tool! just drag table to the command window or a opened .prg file DataExplorer will fill the access to within 🙂

just select all (Ctrl+A) and right click and select Execute Selection from the right click menu.. enjoy it..

* This script handles the ADO Connection and uses a CursorAdapter object
* to retrieve data to a cursor.

Public oCA As CursorAdapter
Local oConn As ADODB.Connection
Local oRS As ADODB.Recordset
Local oComm As ADODB.Command
Local oException As Exception
Local cConnString

* Handle connections - insert connection code
*-cConnString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"+;
"Data Source=D:\Depomatik.sdf"

cConnString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"+;
"Data Source=D:\SOYKAN\MYSOFTWARE\DEPOMATIK_MOBILE_NET\DepomatikNet\DepomatikNet\bin\Debug\Depomatik.sdf"

oConn = Createobject('ADODB.Connection')

* Ensure that you handle userid and password if not
* specified in connection string.
* ex. oConn.Open(cConnString, userid, password)
oComm = Createobject("ADODB.Command")
oComm.ActiveConnection = oConn

oRS = Createobject("ADODB.Recordset")
oRS.Datasource.CursorLocation = 3 &&adUseClient
oRS.Datasource.LockType = 3 &&adLockOptimistic
oRS.ActiveConnection = oConn

oCA.DataSourceType = "ADO"
oCA.Datasource = oRS
oCA.MapBinary = .T.
oCA.MapVarchar = .T.
oCA.SendUpdates = .T.
oCA.KeyFieldList = "MyGuid" && Put the Key Field list here
oCA.WhereType = 1 && Key Fields

oCA.Alias = "CARI"
oCA.SelectCmd = "SELECT * FROM CARI"
oCA.InsertCmdDataSourceType = "ADO"
oCA.UpdateCmdDataSourceType = "ADO"
oCA.DeleteCmdDataSourceType = "ADO"
oCA.RefreshCmdDataSourceType = "ADO"

oCA.InsertCmdDataSource = oComm
oCA.UpdateCmdDataSource = oComm
oCA.DeleteCmdDataSource = oComm
oCA.RefreshCmdDataSource = oComm

If !oCA.CursorFill(.F.,.F.,-1,oComm)
* Replace with error code here
Local laError
Dimension laError[1]
* Replace with user code here. Code below allows for
* you to edit and send updates to the backend.
Local laFlds,lcStr,lnFldCount,i
Dimension laFlds[1]
lcStr2 = ""
For i = 1 To lnFldCount
lcStr = lcStr + laFlds[m.i,1] + ","
lcStr2 = lcStr2 + laFlds[m.i,1] + " CARI."+laFlds[m.i,1]+"," && There should be SPACE before CARI
oCA.UpdatableFieldList = Left(lcStr , Len(lcStr )-1) && To remove last comma
oCA.UpdateNameList = Left(lcStr2, Len(lcStr2)-1) && To remove last comma


Catch To oException
* Replace with exception handling code here

* Add user code here.
* Note: cursors created by CursorAdapter object are closed when object is released.


One thought on “>How to display SDF file (SQLCE) content via VFP CursorAdapter

  1. Excelent. But a question: Whats is the name of the connection?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s