Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
OLEDB: how to get last auto-increment value after INSERT
Versions des environnements
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
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement