#Define SQLCONNECTION "Driver=SQL Server;Integrated Security=SSPI;"+; "Database=Pubs; Server=servername" Local lnHandle lnHandle = SQLSTRINGCONNECT(SQLCONNECTION) SQLEXEC(lnHandle,'select * from Titles','crsTitles') *Let's show what we have got BROWSE TITLE 'Contents of Titles Before Update' m.BookType = 'psychology' m.Amt = 1 && 1 $ change in price *Now we'll decrease price by m.Amt $ where type is m.BookType *First let's check again this set before update SQLEXEC(lnHandle,"select * from Titles where type = ?m.BookType",'crsTitles') BROWSE TITLE 'Filtered Contents of Titles Before Update' *OK now let's decrease the prices and update SQLEXEC(lnHandle,"update Titles set price = price - ?m.Amt where type = ?m.BookType") *Check what we've done SQLEXEC(lnHandle,"select * from Titles where type = ?m.BookType",'crsTitles') BROWSE TITLE 'Filtered Contents of Titles After Update - decrease' * Restore prices SQLEXEC(lnHandle,"update Titles set price = price + ?m.Amt where type = ?m.BookType") *Check what we've done SQLEXEC(lnHandle,"select * from Titles where type = ?m.BookType",'crsTitles') * We're done disconnect SQLDisconnect(lnHandle) BROWSE TITLE 'Filtered Contents of Titles After Update - restore' function CheckError local ix, lcMsg local array arrErr[1] aerror(arrErr) set textmerge to memvar lcMsg noshow set textmerge on for ix =1 to 6 && aError returns 7 elems -we need first 6 at most for ODBC \<<arrErr[ix]>> endfor set textmerge to set textmerge off messagebox(lcMsg)SPT (This one is similar to RV). Promotes SPT to an updatable cursor (like any other local view)
m.csql = "SELECT EmployeeID, LastName, FirstName," + ; "Title, TitleOfCourtesy, BirthDate," + ; "Hiredate, Address, City, Region," + ; "PostalCode, Country, HomePhone," + ; "Extension, Photo, Notes," + ; "ReportsTo, PhotoPath FROM dbo.Employees" lnHandle=Sqlstringconnect('DRIVER=SQL Server;SERVER=servername;'+; 'DATABASE=Northwind;Trusted_Connection=Yes') SQLExec(lnHandle,cSQL,'v_emp') * These properties are set for you by VFP if you use RV * With SPT you need to write yourself to make it an updatable cursor CursorSetProp('KeyFieldList','Employeeid','v_emp') CursorSetProp('WhereType',1,'v_emp') CursorSetProp('Tables','employees','v_emp') CursorSetProp("UpdateNameList", ; "employeeID employees.employeeid,"+; "Firstname employees.FirstName,"+; "Lastname employees.Lastname,"+; "BirthDate employees.birthdate",'V_emp') CursorSetProp('UpdatableFieldList',"Firstname,Lastname,BirthDate",'v_emp') CursorSetProp('SendUpdates',.T.,'v_emp') CursorSetProp('Buffering',5,'v_emp') * Edit here Browse title 'Edit Firstname,Lastname,BirthDate fields' Tableupdate(2,.T.,'v_emp') SQLExec(lnHandle,'select * from dbo.employees','afterupdate') SQLDisconnect(lnHandle) * Check updates Select afterupdate Browse 'New contents of employees'And finally an ADO sample using datagrid (very simple one, no erro check validation etc) :
#Define OLEDBCONNECTSTRING 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=Northwind; Data Source=cetin\cetin' oForm = Createobject('frmSample') oForm.Show Read Events Define Class frmSample As Form Top = 0 Left = 0 Height = 400 Width = 500 DoCreate = .T. Caption = "Form1" Name = "Form1" Add Object myDataGrid As OleControl With ; Top = 10, ; Left = 10, ; Height = 380, ; Width = 480, ; OleClass = 'MSDataGridLib.DataGrid',; Name = "myDataGrid" Procedure Init #Define OLEDBCONNECTSTRING 'Provider=SQLOLEDB.1;Integrated Security=SSPI;'+; 'Initial Catalog=Northwind; Data Source=servername' This.AddProperty('oConn',Createobject('ADODB.Connection')) This.AddProperty('oRS',Createobject('ADODB.RecordSet')) With This.oConn .ConnectionString = OLEDBCONNECTSTRING .Mode = 16 .Open Endwith With This.oRs .ActiveConnection = This.oConn .Source = 'select * from customers' .CursorLocation= 3 && adUseClient .CursorType= 3 .LockType= 4 && adLockBatchOptimistic .Open Endwith Local oRs As ADODB.Recordset With This.myDataGrid .Datasource=This.oRs .Caption = "Customers Table" Endwith Endproc Procedure QueryUnload If Messagebox('Save ?',4+32,'Save changes') = 6 This.oRs.UpdateBatch Endif This.oConn.Close Clear Events Endproc EnddefineWith VFP8 even ADO cursors are easy to cope with :)