Page 1 of 1

PB5.31; ADOmate; @@IDENTITY; MS SQL Server;

Posted: Tue Sep 29, 2015 10:53 am
by HanPBF
Hello,

as PureBasic does not natively support connection to Microsoft SQL Server nor ORACLE database, I use for a SQL Server connection ADOmate.

When I insert a row into a table leaving ID off cause it is an identity field, how can I get the last number generated.

I tried calling ADOmate_DatabaseQuery with "select @@IDENTITY" after inserting data, but got no correct answer (only type mismatch error).
A convert lead to NULL only.

Does someone ran into this problem before?

Thanks in advance,
regards

Re: PB5.31; ADOmate; @@IDENTITY; MS SQL Server;

Posted: Wed Sep 30, 2015 12:10 am
by swan
This is how I did it:

Code: Select all

          If ADOmate_DatabaseQuery(MSSQL_Connection, "SELECT @@IDENTITY AS 'ID' From dbo.positions", #adOpenStatic)
            sw_positionID.l = ADOmate_GetDatabaseLong(MSSQL_Connection, 0)
          EndIf