Search code examples
sqlvb.netoledb

How to get last auto increment value in a table? VB.NET


How would you get the last Primary Key/Auto Increment value in a table using OleDb?

I need to get this value so I can create a folder for a record before it is added so that files can be copied to the folder when it is added.

Any idea? I have tried as following.

@@Identity 'Need to insert a record first and I can't do that without copying the files first SELECT SCOPE_IDENTITY() 'Doesn't work with OleDb

This is the error message I get:

enter image description here


Solution

  • I think this might work:

    SELECT MAX(ID) FROM MyTable