Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating a SQL Database.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 6 SP3
OS:
Windows XP SP1
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
00971565
Message ID:
00971764
Vues:
17
Another option is to use SQLEXEC() to create a cursor, then you can modify the following code to make that cursor updatable. For ALL my tables, I use a surrogate numeric PK that is always named KeyID and I do not make that field updatable because it is automatically generated by the server. Then you can use APPEND, DELETE, REPLACE, TABLEUPDATE(), TABLEREVERT(), etc.
LPARAMETERS tcCursor, tcTable, tlUpdateKey
IF VARTYPE(tcCursor) <> 'C'
   RETURN .f.
ENDIF
IF VARTYPE(tcTable) <> 'C'
   RETURN .f.
ENDIF
IF NOT USED(tcCursor)
   RETURN .f.
ENDIF
CURSORSETPROP('Tables', tcTable)
** The next property must include every remote
** field matched with the cursor field.
LOCAL lcFields, lcUpdate, llRetVal
lcFields = ''
lcUpdate = ''
FOR lnI = 1 TO FCOUNT(tcCursor)
   IF NOT EMPTY(lcFields)
      lcFields = lcFields + ', '
   ENDIF
   lcFields = lcFields + FIELD(lnI, tcCursor) + ' ' ;
            + tcTable + '.' + FIELD(lnI, tcCursor)
   IF UPPER(FIELD(lnI, tcCursor)) == 'KEYID'
      IF NOT tlUpdateKey
         LOOP
      ENDIF
   ENDIF
   IF NOT EMPTY(lcUpdate)
      lcUpdate = lcUpdate + ', '
   ENDIF
   lcUpdate = lcUpdate + FIELD(lnI, tcCursor)
ENDFOR
llRetVal = CURSORSETPROP('UpdateNameList', lcFields, tcCursor)
llRetVal = CURSORSETPROP('KeyFieldList', 'KeyID', tcCursor)
** The next property specifies which fields can be updated.
llRetVal = CURSORSETPROP('UpdatableFieldList', lcUpdate, tcCursor)
** The next property enables you to send updates.
llRetVal = CURSORSETPROP('SendUpdates', .T., tcCursor)
llRetVal = CURSORSETPROP('UpdateType', 1, tcCursor)
llRetVal = CURSORSETPROP('WhereType', 1, tcCursor)
RETURN llRetVal
Mark McCasland
Midlothian, TX USA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform