I have tested the @@identity on Access97 and it ALWAYS returns 0. Here is my
code.
<%
Option Explicit
Dim Conn, SQL, Rs,llID
Set Conn = CreateObject("ADODB.Connection")
Dim sConnection
Dim connPath
set conn = server.createObject("adodb.connection")
'Live
connPath=("test1.mdb")
sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath(connPath) & ";" & _
"Persist Security Info=False"
Conn.Open(sConnection)
' Insert a new record into the table
SQL = "INSERT INTO tblid (fldData) VALUES ('whatever')"
' Execute the SQL statement
Conn.Execute(SQL)
' Get the @@IDENTITY. The key statement is the one below
' llID will contain the new identity value inserted
SQL = "SELECT @@IDENTITY AS NewID"
Set Rs = Conn.Execute(SQL)
llID = Rs.Fields("NewID").value
' Close the connection
Conn.Close()
Set Conn = Nothing
response.write llID
%>
----- Original Message -----
From: "Ken Schaefer" <[EMAIL PROTECTED]>
To: "ActiveServerPages" <[EMAIL PROTECTED]>
Sent: Tuesday, August 20, 2002 3:54 AM
Subject: Re: Getting last ID from an INSERT into an Access database
> Do you know how long this would take you to test? Probably less time that
it
> took for you to write the email and for it to appear on the list!
>
> For the record, I haven't tested this myself, but I know someone who has
and
> they say that it doesn't work. Access97 uses the Jet v3 engine, and whilst
> you can use the OLEDB.4.0 Provider to connect to Jet v3, the actual
database
> engine doesn't support @@Identity
>
> Cheers
> Ken
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: "Kangaroo's Dream" <[EMAIL PROTECTED]>
> Subject: Re: Getting last ID from an INSERT into an Access database
>
>
> : Will this work with access97 with an oledb 4.0
> :
> : ----- Original Message -----
> : From: "David L. Penton" <[EMAIL PROTECTED]>
> : To: "ActiveServerPages" <[EMAIL PROTECTED]>
> : Sent: Monday, August 19, 2002 3:53 PM
> : Subject: RE: Getting last ID from an INSERT into an Access database
> :
> :
> : > Sure you can...in most situations. But if you can use the @@IDENTITY,
> it
> : is
> : > far faster and creates less traffic on the wire.
> : >
> : > David L. Penton, Microsoft MVP
> : > JCPenney Application Specialist / Lead
> : > "Mathematics is music for the mind, and Music is Mathematics for the
> : > Soul. - J.S. Bach"
> : > [EMAIL PROTECTED]
> : >
> : > Do you have the VBScript Docs or SQL BOL installed? If not, why not?
> : > VBScript Docs: http://www.davidpenton.com/vbscript
> : > SQL BOL: http://www.davidpenton.com/sqlbol
> : >
> : >
> : > -----Original Message-----
> : > From: Michael Elfial [mailto:[EMAIL PROTECTED]]
> : >
> : > Or just use
> : > recordset.Open ...
> : > recordset AddNew
> : > recordset("field").Value = something
> : > ...
> : > recordset.Update
> : > ID = recordset("TheIDField").Value
> : >
> : >
> : >
> : > -----Original Message-----
> : > From: Nick Middleweek [mailto:[EMAIL PROTECTED]]
> : >
> : > Hello,
> : >
> : > What is the best way to get the value of the unique ID field from an
> : Access
> : > database using ADO/SQL after INSERTing a new record.
> : >
> : > Does IDENTITY exist in Access?
> : >
> : >
> : > Thanks,
> : > Nick
>
>
>
> ---
> You are currently subscribed to activeserverpages as:
[EMAIL PROTECTED]
> To unsubscribe send a blank email to
%%email.unsub%%
>
---
You are currently subscribed to activeserverpages as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]