>* 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 oException AS Exception >LOCAL cConnString > >* Handle connections - insert connection code >cConnString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"+; > "Data Source=C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Samples\northwind.sdf" >TRY > oConn = createobject('ADODB.Connection') > > * Ensure that you handle userid and password if not > * specified in connection string. > * ex. oConn.Open(cConnString, userid, password) > oConn.Open(cConnString) > > oRS = CREATEOBJECT("ADODB.Recordset") > oRS.DataSource.CursorLocation = 3 &&adUseClient > oRS.DataSource.LockType = 3 &&adLockOptimistic > oRS.ActiveConnection = oConn > > oCA=CREATEOBJECT("CursorAdapter") > oCA.DataSourceType = "ADO" > oCA.DataSource = oRS > oCA.MapBinary = .T. > oCA.MapVarchar = .T. > > oCA.Alias = "customers" > oCA.SelectCmd = "SELECT * FROM customers" > > IF !oCA.CursorFill() > * Replace with error code here > LOCAL laError > DIMENSION laError[1] > AERROR(laError) > MESSAGEBOX(laError[2]) > ELSE > * 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] > lnFldCount=AFIELDS(laFlds) > lcStr="" > FOR i = 1 TO lnFldCount > lcStr = lcStr + laFlds[m.i,1] + "," > ENDFOR > oCA.UpdatableFieldList = lcStr > BROWSE NORMAL NOWAIT > ENDIF > >CATCH TO oException > * Replace with exception handling code here > MESSAGEBOX(oException.Message) > >ENDTRY > >* Add user code here. >* Note: cursors created by CursorAdapter object are closed when object is released. >Cetin