Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL & connection datasets to VFP applications
Message
De
31/03/2004 05:01:18
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
31/03/2004 03:11:40
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00891088
Message ID:
00891102
Vues:
23
>Hi
>
>I've successfully used SQLStringConnect() to retreive data from my SQL server. However, what I want to know is:
>
>How do I tie a control on a form to the live data on my SQL server? For example, the dataset returned is called ltMyData. I can set the datasource property of a textbox to ltMyData.User_Name. That's straightforward, but how would I apply any changes to this textbox to my SQL server?
>
>Regards
>
>Derek

Derek,
Since you say SQLStringConnect() then I assume you mean SPT (at a beginner phase with RV it's straightforward, accept view as any view).
With SPT you have to call an update command. There are multiple ways. Let's start with one :

lcCommand = 'update myTable set'+'+;
' User_Name = ?ltMyData.User_Name'+;
' where PKID = ?ltMyData.PKID'
SQLExec(m.lnHandle, m.lcCommand)

This is the hard way but serves as a skeleton. Easy way is to promote your dataset cursor as an updatable one and simply call tableupdate() as usual. To promote it as an updatable one you've to set :
'KeyFieldList','Tables','UpdateNameList','UpdatableFieldList' + 'WhereType' and 'SendUpdates' properties of cursor. Easy way of creating these properties (if you don't want to do manually like me:) is to create a temp dbc and create an RV there using the designer. Then get the code using gendbc. There is a sample below how this is used :
lnHandle=Sqlstringconnect('DRIVER=SQL Server;'+;
   'SERVER=servername;DATABASE=pubs;Trusted_Connection=Yes')
SQLExec(lnHandle,'select * from dbo.authors','v_authors')
Select v_authors
* Could index a view - do it before setting buffering to table level
Index On au_fname tag fname
Index On au_lname tag lname
Set Order To 0

On Key Label 'F2' set order to tag fname
On Key Label 'F3' set order to tag lname
On Key Label 'F4' set order to 0
On Key Label 'F5' browse


CursorSetProp('KeyFieldList','au_id','v_authors')
CursorSetProp('WhereType',1,'v_authors')
CursorSetProp('Tables','authors','v_authors')

CursorSetProp("UpdateNameList", ;
  "au_id    authors.au_id,"+;
  "au_lname authors.au_lname,"+;
  "au_fname authors.au_fname,"+;
  "contract authors.contract",'V_authors')

CursorSetProp('UpdatableFieldList','au_fname,au_lname,contract','v_authors')
CursorSetProp('SendUpdates',.T.,'v_authors')
CursorSetProp('Buffering',5,'v_authors')
Browse Title 'Before updated'

On Key Label 'F2'
On Key Label 'F3'
On Key Label 'F4'
On Key Label 'F5'

Tableupdate(2,.T.,'v_authors')
SQLExec(lnHandle,'select * from dbo.authors','afterupdate')
SQLDisconnect(lnHandle)
Select afterupdate
Browse Title 'After Updated'
This sample uses browse just for ease. Since it's a cursor bind to whatever you like.
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform