Click here to Skip to main content
15,898,374 members
Home / Discussions / Database
   

Database

 
GeneralRe: Handle SQL errors with severity 10 Pin
Colin Angus Mackay23-Mar-05 13:03
Colin Angus Mackay23-Mar-05 13:03 
GeneralRe: Handle SQL errors with severity 10 Pin
_J_23-Mar-05 21:31
_J_23-Mar-05 21:31 
GeneralRow ID after INSERT to database Pin
Abyss22-Mar-05 21:00
Abyss22-Mar-05 21:00 
GeneralRe: Row ID after INSERT to database Pin
_J_23-Mar-05 1:45
_J_23-Mar-05 1:45 
GeneralRe: Row ID after INSERT to database Pin
Abyss23-Mar-05 2:19
Abyss23-Mar-05 2:19 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin23-Mar-05 3:37
Jeff Martin23-Mar-05 3:37 
GeneralRe: Row ID after INSERT to database Pin
_J_23-Mar-05 3:53
_J_23-Mar-05 3:53 
GeneralRe: Row ID after INSERT to database Pin
Abyss23-Mar-05 21:25
Abyss23-Mar-05 21:25 
Hi,

Many thanks for help. I'm a C++ programer and the suggested methods for some reason fail.
I try to get the inserted row's ID (primary key) which was inserted to a table.
I tried the following API calls immediately after insert. I use the same m_hStmn for the insert and the select query.

This call is successfull however when I query the returned value using the SQLFetch and SQLGetData the returned SQLINTEGER is always zero!?
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT @@IDENTITY AS 'Ident'"), SQL_NTS)

I tried to use the more save SCOPE_IDENTITY() function, however these API calls fail.
The driver returns (for Access table) undefined function.
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT SCOPE_IDENTITY()"), SQL_NTS)<br />
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT SCOPE_IDENTITY() As [Ident]"), SQL_NTS)


In this case I got from the driver one parameter missing error code:
SQLExecDirect(m_hStmn, (SQLTCHAR*)_T("SELECT SCOPE_IDENTITY"), SQL_NTS)

Can anybody explain how can I correctly get the inserted row's ID? Why the above calls fail Cry | :(( ?

Thanks,
Abyss
GeneralRe: Row ID after INSERT to database Pin
Huseyin Altindag24-Mar-05 0:33
Huseyin Altindag24-Mar-05 0:33 
GeneralRe: Row ID after INSERT to database Pin
Abyss24-Mar-05 1:33
Abyss24-Mar-05 1:33 
GeneralRe: Row ID after INSERT to database Pin
Huseyin Altindag24-Mar-05 1:42
Huseyin Altindag24-Mar-05 1:42 
GeneralRe: Row ID after INSERT to database Pin
Abyss24-Mar-05 1:52
Abyss24-Mar-05 1:52 
GeneralRe: Row ID after INSERT to database Pin
Mike Dimmick24-Mar-05 2:22
Mike Dimmick24-Mar-05 2:22 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 3:19
Jeff Martin24-Mar-05 3:19 
GeneralRe: Row ID after INSERT to database Pin
Abyss24-Mar-05 3:38
Abyss24-Mar-05 3:38 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 4:06
Jeff Martin24-Mar-05 4:06 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 3:15
Jeff Martin24-Mar-05 3:15 
GeneralRe: Row ID after INSERT to database Pin
Abyss24-Mar-05 3:45
Abyss24-Mar-05 3:45 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 4:08
Jeff Martin24-Mar-05 4:08 
QuestionColin Angus Mackay ???? Pin
WDI22-Mar-05 9:11
WDI22-Mar-05 9:11 
AnswerRe: Colin Angus Mackay ???? Pin
Jeff Martin22-Mar-05 9:57
Jeff Martin22-Mar-05 9:57 
GeneralRe: Colin Angus Mackay ???? Pin
WDI22-Mar-05 10:34
WDI22-Mar-05 10:34 
QuestionColin Angus Mackay ???? Pin
WDI22-Mar-05 9:08
WDI22-Mar-05 9:08 
AnswerRe: Colin Angus Mackay ???? Pin
anonymous19823-Mar-05 9:18
anonymous19823-Mar-05 9:18 
GeneralSql stored procedure vs triggers vs functions Pin
jinnyb22-Mar-05 5:55
jinnyb22-Mar-05 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.