Windows ODBC Drivers for BigCommerce - getting new IDENTITY value?

Discussion of open issues, suggestions and bugs regarding usage of ODBC Drivers
Post Reply
jgoemaat
Posts: 5
Joined: Mon 17 Dec 2018 23:08

Windows ODBC Drivers for BigCommerce - getting new IDENTITY value?

Post by jgoemaat » Tue 29 Jan 2019 17:29

Hello!

Using your ODBC driver, is it possible to get the IDENTITY value of the most recently inserted row?

For example, when I INSERT a row to the Categories tables, how do I get the new "Id" value of the record I inserted?

I'm assuming a "hack" would be to pull the max value from the table as the IDENTITY columns are probably sequential/increasing values, but normally in VBA, I can use a command like this after doing the insert:

Code: Select all

newID = db.OpenRecordset("SELECT @@IDENTITY").Fields(0)
Instead of DAO, I could try using ADO in VBA, but wanted to ask before spending a lot of time trying numerous ways.

Other than that, the product is working great so far and had great value!

Thanks!

MaximG
Devart Team
Posts: 1316
Joined: Mon 06 Jul 2015 11:34

Re: Windows ODBC Drivers for BigCommerce - getting new IDENTITY value?

Post by MaximG » Wed 30 Jan 2019 14:05

You can retrieve the primary key value of the inserted record with help of the "Returning" construct, for example:

Code: Select all

     Insert Into  Brands (Name) Values ('New Name Value') Returning ID 

Post Reply