>>lnHandle=SQLStringConnect('DRIVER=SQL Server;SERVER=servernamehere;'+; 'DATABASE=pubs;Trusted_Connection=Yes') >>SQLExec(lnHandle, "select * from employee", 'myEmployee') >>SQLDisconnect(lnHandle) >> >>select myEmployee >>browse >>>>Cetin
#Define SQLCONNECTION "Provider=SQLOLEDB.1;Integrated Security=SSPI;"+; "Persist Security Info=False;"+; "Initial Catalog=Pubs; Data Source=cetin\cetin" Local oRecordSet As ADODB.Recordset, oConnection As ADODB.Connection oRecordSet = Createobject("adodb.recordset") oConnection = Createobject("adodb.connection") With oConnection .ConnectionString = SQLCONNECTION .Mode = 16 && adModeShareDenyNone .Open() Endwith With oRecordSet .ActiveConnection = oConnection .LockType= 4 && adLockBatchOptimistic .CursorLocation= 3 && adUseClient .CursorType= 2 && adOpenDynamic .Source = 'select * from Titles' .Open *Let's show what we have got *HFlex activex grid is one we could use to 'browse' ShowMe('Contents of Titles Before Update',oRecordSet) *Now we'll increase price by 1$ where type = 'psychology' * PS: This is one way of doing it, not the only way. .Filter = "type = 'psychology'" *First let's check again this set before update ShowMe('Filtered Contents of Titles Before Update',oRecordSet) *OK now let's increase the prices and update .MoveFirst Do While !.Eof .Fields('price').Value = .Fields('price').Value + 1 .MoveNext && skip:) Enddo .UpdateBatch() && TableUpdate(.t.) *And check updated set .Requery() && Requery to be sure we're seeing updated content Endwith ShowMe('Filtered Contents of Titles After Update',oRecordSet) Function ShowMe Lparameters tcCaption,toRecordset oForm = Createobject('myForm', tcCaption,toRecordset) oForm.Show Read Events Endfunc Define Class myform As Form Height = 450 Width = 750 Name = "Form1" Add Object hflex As OleControl With ; Top = 10, Left = 10, Height = 430, Width = 730, Name = "Hflex", ; OleClass = 'MSHierarchicalFlexGridLib.MSHFlexGrid' Procedure Init Lparameters tcCaption,toRecordset This.Caption = tcCaption This.hflex.Datasource = toRecordset Endproc Procedure QueryUnload Clear Events Endproc EnddefineNow let's do the same with SPT (this time decreasing prices by 1$ that we just increased) :
#Define SQLCONNECTION "Driver=SQL Server;Integrated Security=SSPI;"+; "Database=Pubs; Server=cetin\cetin" 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' *Now we'll decrease price by 1$ where type = 'psychology' *First let's check again this set before update SQLEXEC(lnHandle,"select * from Titles where type = 'psychology'",'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 - 1 " +; " where type = 'psychology'") *Check what we've done SQLEXEC(lnHandle,"select * from Titles "+; " where type = 'psychology'",'crsTitles') * We're done disconnect SQLDisconnect(lnHandle) BROWSE TITLE 'Filtered Contents of Titles After Update'Remember these are samples and only one way of doing it. However I must admit for myself SPT version is much more easier to handle with VFP controls/commands/functions. ie: It takes only a few lines of additional code to promote the cursor you got from SQL server with 'select ...' to an updatable cursor. You could simply use that cursor if it were a VFP table in your forms :) With ADO it's much more tricky (and up to date I didn't see a solid reason to use ADO over SPT except few special cases - there are some benchmarks on foxvikis.com that you might check).