473,395 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Retrieve last inserted id

Hi All,

Using classic ASP applciation with DB2 (just adding it to the apps
quiver of DBs). I am trying to do an insert and then retrieve the
auto-increment field's value using the standard ADO call of

rsForm.Update
nFormStructRecId = rsForm("record_id")
rsForm.Close

The problem is that the value comes back as 0. How should I fix the
problem?

Regards

phpster

Nov 12 '05 #1
3 3998
lostboy wrote:
Hi All,

Using classic ASP applciation with DB2 (just adding it to the apps
quiver of DBs). I am trying to do an insert and then retrieve the
auto-increment field's value using the standard ADO call of

rsForm.Update
nFormStructRecId = rsForm("record_id")
rsForm.Close

The problem is that the value comes back as 0. How should I fix the
problem?

Regards

phpster

Which version of DB2 are you on.
Also what's the table definition (do you use a SEQUENCE or an IDENTITY
columns)?
How does the INSERT statement look like.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
v8.1 windows

ado insert
sequences

CODE
sSQL = "select * from form_structure where form_id = '" & nHeaderID
& "' and field_name = '" & sFldName & "' "

'use ADO to get the record id number back

rsForm.open sSQL, PortalDB, adOpenDynamic, adLockOptimistic

if rsForm.EOF and rsForm.BOF then
rsForm.AddNew
' sThisSortOrder = 999 'move the newly added record to last
place
end if

rsForm("field_name") = lcase(sFldName)
rsForm("sort_order") = nSortCounter 'current sort order
rsForm("form_id") = nHeaderID
rsForm("data_type") = lcase(sDefaultDataType)

rsForm.Update

nFormStructRecId = rsForm("record_id")

Bastien

Nov 12 '05 #3
lostboy wrote:
v8.1 windows

ado insert
sequences

CODE
sSQL = "select * from form_structure where form_id = '" & nHeaderID
& "' and field_name = '" & sFldName & "' "

'use ADO to get the record id number back

rsForm.open sSQL, PortalDB, adOpenDynamic, adLockOptimistic

if rsForm.EOF and rsForm.BOF then
rsForm.AddNew
' sThisSortOrder = 999 'move the newly added record to last
place
end if

rsForm("field_name") = lcase(sFldName)
rsForm("sort_order") = nSortCounter 'current sort order
rsForm("form_id") = nHeaderID
rsForm("data_type") = lcase(sDefaultDataType)

rsForm.Update

nFormStructRecId = rsForm("record_id")

Bastien

Bear with me I'm ADO ignorant.
If you are using sequence how do you generate teh new value?
Do you have an INSERT trigger on FORM_STRUCTURE?
You can get the value back through two means:
Select back "SELECT PREVIOUS VALUE FOR <seqname> FROM SYSIBM.SYSDUMMY1"
or Do the insert expliictly:

SELECT <idcol> FROM NEW TABLE(INSERT INTO FORM_STRUCTURE .....)

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
6
by: Maurizio Faini | last post by:
I have a little problem. there is a way to get last id inserted into db or i have to make a new query? I explain better my question: in vbscript using sqlserver2000 i can use this code: ...
5
by: nicholas | last post by:
I would like to insert a new record in a Ms Access database and retrieve the newly created ID (autonumber). I would like to do it in VB.NET for an ASP.NET page. ( no asp) I found several...
3
by: bazubwabo | last post by:
hi everybody , could u please help me to find out the error on my asp codes,i can't retrieve the inserted values. Here is below the code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!DOCTYPE...
2
by: feets | last post by:
OK first time poster, so hello everyone in advance. Right i'm sure this is a simple problem to solve, but I'm just getting the hang of SQL 2000. What I've got is a form where I input the values and...
2
by: Daz | last post by:
Hi. I would like to know how to obtain a reference to (or at least, element type of) the last node which was inserted into the document. I am using an event listener to listen for dom inserts,...
2
by: imranabdulaziz | last post by:
Dear all, i am using asp.net ,C# (VS 2005) and sql server 2005. i have written sp for inserting the the data which written last inserted idendity no. i would like to which method should i...
20
by: canabatz | last post by:
hi all !! i got my results like that 1 user0 55 2 user1 53 3 user2 49 4 user2 48 5 user3 47 <------- last inserted row 6 user4 46
4
by: questionit | last post by:
How do i retreive 10 rows from a table using SQL SELECT Names from Customers... how do i change it to retrieve only 'n' number of rows? Please suggest an easy method Thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.