Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OLEDB: how to get last auto-increment value after INSERT
Message
 
À
01/10/2015 16:22:10
Joe Kaufman
Bell Laboratories Inc.
Wisconsin, États-Unis
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 8 SP1
OS:
Windows 7
Network:
Novell 6.x
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01625339
Message ID:
01625340
Vues:
60
>Hey all,
>
>I am starting in earnest to use .NET (C#) for developing applications. We do not have SQL Server in place yet, so we will need to get started using Windows Forms applications against DBF-based data. I am liking the performance so far with using the VFP OLEDB provider within Visual Studio 2015, and have developed a framework to perform SELECTs, INSERTs, UPDATEs, and DELETEs. It's all working pretty well, and I am impressed by how close speeds are to native Foxpro data access.
>
>But a potential showstopper is this: After I INSERT a new row into a table with an auto-incremented key field, how do I get back the new key that was generated? This is 100% necessary in many scenarios, and one obviously cannot try USE and GOTO BOTTOM or check the record pointer in this environment.
>
>According to my searches, doing a SQL statement "SELECT @@IDENTITY" works for the JET 4.0 database layer (e.g. against Access), but I tried that query and end up with the error:
>
>"Command contains unrecognized phrase/keyword"
>
>I cannot find any examples online of getting the last key generated for the table I just inserted into, and I don't want to have to resort to some sort of silly "SELECT MAX(Key)..." methodology. Surely there must be a way to get the last key inserted? Please help!
>
>Much appreciated...
>
>Thanks,
>JoeK

VFP didn't have @@IDENTITY
you have to use:
SELECT Key FROM Table WHERE Key = GETAUTOINCVALUE()
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform