[freetds] SELECT @@IDENTITY AS InsertID

Shaun Craig s.craig at andronics.com
Thu Oct 6 10:49:46 EDT 2005


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.


More information about the FreeTDS mailing list