Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use the CursorAdapter
Message
From
07/11/2002 04:27:19
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/11/2002 23:59:35
Peter Easson
Catalina Trading
Sydney, Australia
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00719501
Message ID:
00719708
Views:
25
>Next Step....
>Browse the resulting Cursor
>Everything works perfectly until you make a change to one of the fields, and you get the message "Cannot Update ADODB.Recordset because it is read-only."
>If you set the Recordset's CursorType to adOpenDynamic and the LockType to adLockOptimistic, a similar problem occurs, except you have to forcefully shutdown VFP8 to kill the cursor because it's 'disconnected' or something.
>
>Wish there was a little book of examples somewhere :-)
>
>Peter Easson

One sample :)
#Define SQLCONNECTION 	"Provider=SQLOLEDB.1;Integrated Security=SSPI;"+;
  "Persist Security Info=False;"+;
  "Initial Catalog=Northwind; Data Source=servernamehere"

*!* ADO CursorAdapter
oXC1 = Createobject('xcADOUpdatable', "vcustomers", SQLCONNECTION, ;
   "select * from customers",;
   "Customers",;
   "CustomerID",;
   "CustomerID, CompanyName, ContactName, ContactTitle",;
   "CustomerID customers.CustomerID, "+;
   "CompanyName customers.CompanyName,"+;
   "ContactName customers.ContactName,"+;
   "ContactTitle customers.ContactTitle")

CursorSetProp("Buffering",5,'vcustomers')
Browse Title 'Before modification'
If ( !Tableupdate(2,.T.,'vcustomers') )
  oXC1.DispError()
Else
  oXC1.CursorFill()
  Browse Title 'After Tableupdate'
Endif

Define Class xcADOUpdatable As CursorAdapter
  AllowUpdate = .T.
  AllowInsert = .T.
  AllowDelete = .T.
  Procedure Init
    Lparameters tcAlias,tcConn, tcSQL,tcTables,;
    tcKeyFieldList,tcUpdatableFieldList,tcUpdateNameList
    This.AddProperty('oConn', Newobject("ADODB.Connection"))
    This.AddProperty('oRS',   Newobject("ADODB.Recordset"))
    With This.oConn
      .ConnectionString = tcConn
      .Mode = 16  && adModeShareDenyNone
      .Open()
    Endwith
    With This.oRS
      .ActiveConnection = This.oConn
      .LockType=3  && adLockOptimistic
      .CursorLocation = 3  && adUseClient
      .CursorType = 2  && adOpenDynamic
    Endwith
    With This
      .Alias = tcAlias
      .Tables = tcTables
      .KeyFieldList = tcKeyFieldList
      .UpdatableFieldList = tcUpdatableFieldList
      .UpdateNameList = tcUpdateNamelist
      .WhereType = 1
      .UpdateType= 1
      .SendUpdates = .T.
      .DataSourceType = "ADO"
      .Datasource = This.oRS
      .SelectCmd = tcSQL
      .CursorFill()
    Endwith
  Endproc

  Procedure DispError
    Local Array errors(1)
    Local lcError
    Aerror(errors)
    lcError = 'Error--------------'
    For ix=1 To 7
      lcError = lcError + Chr(13)+Transform(errors[ix])
    Endfor
    lcError = lcError + Chr(13) + 'Error--------------'
    Messagebox(lcError)
  Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform