Skip to Content.
Sympa Menu

freetds - [freetds] SELECT @@IDENTITY AS InsertID

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Shaun Craig <s.craig AT andronics.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] SELECT @@IDENTITY AS InsertID
  • Date: Thu, 06 Oct 2005 15:49:46 +0100

Hi all,

I've got an insert statement with SELECT @@IDENTITY AS InsertID at the end as I want to know what row the record was inserted into. I know the line I use works as i've tested it through tsql and its gives me back the correct row number. The problem is in my C code i cant get the value passed back to me, this is my code so far.

DBINT InsertID;
journey_id //global variable of type int
Query //which contains my insert statement and SELECT @@IDENTITY AS InsertID

dbfcmd(dbconn, Query)
dbsqlexec(dbconn)
dbresults(dbconn)

//Now i'm trying to bind the returned row number into InsertID
dbbind(dbconn, 1, INTBIND, (DBINT)0, (BYTE *)& InsertID);

if (dbnextrow(dbconn) != NO_MORE_ROWS)
{
journey_id = InsertID;
}

Unfortunately my program crashes either at the bind or dbnextrow() as i'm doing something wrong.

Any help would be appreciated as this is holding me back from other stuff, thanks.

Shaun.




Archive powered by MHonArc 2.6.24.

Top of Page