473,563 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
nFormStructRecI d = 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 4009
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
nFormStructRecI d = 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, adLockOptimisti c

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

rsForm("field_n ame") = lcase(sFldName)
rsForm("sort_or der") = nSortCounter 'current sort order
rsForm("form_id ") = nHeaderID
rsForm("data_ty pe") = lcase(sDefaultD ataType)

rsForm.Update

nFormStructRecI d = 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, adLockOptimisti c

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

rsForm("field_n ame") = lcase(sFldName)
rsForm("sort_or der") = nSortCounter 'current sort order
rsForm("form_id ") = nHeaderID
rsForm("data_ty pe") = lcase(sDefaultD ataType)

rsForm.Update

nFormStructRecI d = 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.SYSDUMMY 1"
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
8731
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware tblSoftware ------------------- ------------------ ---------------------- PID PName PID* SID* SID SWName --- ...
6
47362
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: varBookmark=rs.Bookmark rs.Update
5
10272
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 examples on the net, but most of them just work with sql-server (@@indentity), or use just asp with includes etc. Hope someone can help me with a...
3
1492
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 HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% connect_string = "Driver={SQL...
2
4368
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 then through a procedure these values are inserted into a table. That's fine. However I now need to open a subform which is linked by the ID field...
2
2951
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, but I am not sure how to check if that last node was a script tag. Please could someone point me in the right direction? Many thanks, and Merry...
2
1540
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 use(reader , nonexecutequery or executescalar ) so that i get that value and display the value in the form. please guide me. thanks
20
3485
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
6885
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
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.