That article needs to be rewritten: the example given will raise an error
due to the inability of Jet to perform batched queries. This example:
<%
fakeValue = 5
set conn = CreateObject("ADODB.Connection")
conn.open "<conn string>"
sql = "INSERT someTable(IntColumn) values(" & fakeValue & ")" & _
VBCrLf & " SELECT @@IDENTITY"
set rs = conn.execute(sql)
response.write "New ID was " & rs(0)
rs.close: set rs = nothing
conn.close: set conn = nothing
%>
needs to be rewritten as:
<%
fakeValue = 5
set conn = CreateObject("ADODB.Connection")
conn.open "<conn string>"
sql = "INSERT someTable(IntColumn) values(" & fakeValue & ")"
conn.execute sql,,129
sql = " SELECT @@IDENTITY"
set rs = conn.execute(sql,,1)
response.write "New ID was " & rs(0)
rs.close: set rs = nothing
conn.close: set conn = nothing
%>
the other john wrote:
Excellent, thanks!
Ray Costanzo [MVP] wrote:
>There's a section about doing this in Access here:
http://www.aspfaq.com/show.asp?id=2174
Ray at work
"the other john" <ki*****@yahoo.comwrote in message
news:11**********************@p79g2000cwp.googleg roups.com...
>>I want to insert a record into a DB and then immediately recall what
the ID is. I have heard that there is a way to do this with SQL
Server (although I haven't done it yet). Unfortunately this is for
Access.
I've done some workarounds for this in the past but want to know if
there are better ways. What I've done in the past is to recall the
file name or something from the FORM collection against the DB
(assuming this file is unique). Using aspupload, if the overwrite
attribute is set for FALSE I can use that as a way to better ensure
the file name is unique as it renames the file if it is not unique.
The problem is I need to to this without aspupload now.
I had thought of recalling the last record ID from the DB on the
FORM side and putting it in a hidden field but this seems risky.
Any suggestions?
Thanks again!
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"