Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CursorAdapter - Native - AutoRefresh
Message
De
05/09/2005 00:27:31
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01046707
Message ID:
01046712
Vues:
257
This message has been marked as the solution to the initial question of the thread.
Rodolfo,

You don't say if you are using VFP8 or VFP9. If it's 9, you can use two properties designed for refreshing cursor fields after an insert -- if you have another key that can be used to uniquely find the record you just inserted.

If you have another unique field in the record being inserted and you already know the value of that field (it is assigned in the cursor before the Tableupdate), you can use that field as the lookup key to find the record just inserted. For example, if you added another field like Extrakey c(10) and inserted SYS(2015) into it, you could have VFP9 CA automatically refresh the cursor record by setting two properties:
oCA = CreateObject("MyCAObj")
oCA.InsertCmdRefreshKeyFieldList = "Extrakey"
oCA.InsertCmdRefreshFieldList = "MyID"
oCA.CursorFill()
Insert Into crs_Table (Extrakey, Name, LastName) ;
  Values (SYS(2015), "Rodolfo","Duarte")
TableUpdate()
Because the value of Extrakey is known (it's in the cursor after the insert statement), CA can automatically use that value to retreive the record just inserted to refresh the cursor with the new autoinc value.

A different approach you might want to experiment with is to make use of the InsertCmdRefreshCmd property to specify a query that matches the Identity field to the last key added (this might work only if you are inserting just one record).

This idea comes from the "New in Nine" Hentzenwerke book, which shows an example of using the @@IDENTITY feature in SQL Server to get the newly-added value):
oCA.InsertCmdRefreshCmd = ;
  "Select MyID from tablename where MyID = @@IDENTITY"
oCA.InsertCmdRefreshFieldList = "MyID"
So, with VFP9's new GETAUTOINCVALUE() function, you MIGHT be able to mimic the same thing in VFP9 against Fox tables (I have not tested this and have no idea if it will work, so I leave it to you as just an idea to explore):
*** THIS CODE NOT TESTED -- JUST AN IDEA TO EXPLORE
oCA.InsertCmdRefreshCmd = ;
  "Select MyID from tablename where MyID = GetAutoIncValue()"
oCA.InsertCmdRefreshFieldList = "MyID"
>Hi,
>
>I have a table (MyId AutoInc, Name C(30), LastName C(30)). I'm using NATIVE data acess.
>
>So, I need to get the MyId value after an Insert like that:
>
>
>oCA = CreateObject("MyCAObj")
>oCA.CursorFill()
>Insert Into crs_Table (Name, LastName) Values ("Rodolfo","Duarte")
>TableUpdate()
>
>
>So, I hope to get my cursor crs_Table updated!
>
>I used the original Builder to configure my Cursor Adapter class. I tried to find something about it seaching UT and VFP help, but no success...
>
>Any advice?
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform