Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2008, 08:19 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default @@IDENTITY use...

Hi All,

I could use a little assistance, I am trying to insert a new record into my access db and am trying to extract the Autonumber ID at the same time. I know this is the not the best way to do it but I am restricted by the clients existing db.

I have been trying multiple ways to do this and come up with numerous errors. Here my code.

varDate = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
SET DbConn = Server.CreateObject("ADODB.Connection")
DbConn.Open "DSN=materials;Password=" & PASS_DB
SET oRS = Server.CreateObject("ADODB.Recordset")
strSQL = "INSERT INTO Materiales" _
       & " (Clave, Concepto, Category, Updated)" _
       & " VALUES ('" & Request.Form("tbClave") & "', '" & Request.Form("taConcepto") & "', " & Request.Form("ddCategory") & ", '" & varDate & "')" _
       & " SELECT @@IDENTITY"
Response.Write strSQL
'Response.End
SET oRS = DbConn.Execute(strSQL)
Response.Write "New ID was " & oRS(0)

This one gives me the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Missing semicolon (;) at end of SQL statement.

But then you put the ; on the end and you get the same error

If you do this:
strSQL = "INSERT INTO Materiales" _
       & " (Clave, Concepto, Category, Updated)" _
       & " VALUES ('" & Request.Form("tbClave") & "', '" & Request.Form("taConcepto") & "', " & Request.Form("ddCategory") & ", '" & varDate & "');" _
       & " SELECT @@IDENTITY;"
You get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Characters found after end of SQL statement.

I am at a loss... Any help would be greatly appreciated

Best Regards,

Paul
 
Old May 3rd, 2008, 06:47 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,

I figured it out for myself, seeing as no one helped me. Just if you are wondering how, here is the code:

varDate = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
nOption = Request.Form("hidWithUnits")
SET DbConn = Server.CreateObject("ADODB.Connection")
DbConn.Open "DSN=materials;Password=" & PASS_DB
SET oRS = Server.CreateObject("ADODB.Recordset")
strSQL = "INSERT INTO Materiales" _
       & " (Clave, Concepto, Category, Updated)" _
       & " VALUES ('" & Request.Form("tbClave") & "', '" & Request.Form("taConcepto") & "', " & Request.Form("ddCategory") & ", '" & varDate & "');"
SET oRS = DbConn.Execute(strSQL)
SET rsData = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT @@IDENTITY AS NewID"
SET rsData = DbConn.Execute(strSQL)
nNewID = rsData("NewID")
rsData.Close
SET rsData = Nothing
oRS.Close
SET oRS = Nothing

Cheers,
Paul





Similar Threads
Thread Thread Starter Forum Replies Last Post
User Identity stonesbg ASP.NET 2.0 Basics 1 February 9th, 2007 11:14 AM
select into and identity joxa83 SQL Server 2000 2 August 30th, 2006 10:08 AM
@@IDENTITY Problem datagram Pro VB.NET 2002/2003 2 May 19th, 2005 01:34 PM
what does identity do amruthhr SQL Server 2000 2 January 6th, 2005 09:45 AM
Identity soccers_guy10 SQL Server 2000 3 September 2nd, 2003 07:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.