Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OLEDB: how to get last auto-increment value after INSERT
Message
From
01/10/2015 16:22:10
Joe Kaufman
Bell Laboratories Inc.
Wisconsin, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
OLEDB: how to get last auto-increment value after INSERT
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 7
Network:
Novell 6.x
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01625339
Message ID:
01625339
Views:
65
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
Next
Reply
Map
View

Click here to load this message in the networking platform