Replies Back to Article

Insert Record With Identity ASP

Does this work?
February 7, 2001 by Bill wpmurphy88

So far not so good - Usual hassles you get with the insert behaviour (error 503 don't try this request at home), but this time there is an error in the SQL at this point:

    MM_editCmd.CommandText = "SET NOCOUNT ON;" & MM_editQuery & ";SELECT@" & "@IDENTITY AS Ident"
    Set rsLastIdent = MM_editCmd.Execute

Got to admit I don't know what is happening - the insert statement I can follow the rest passes me by.

I'm using MySQL- the latest(ish) release does this explain it?

How do you make use of the ident? compound keys and others
February 7, 2001 by Bill wpmurphy88

I am assuming that I can pass the id to another page and use this in data operations - for instance - I insert a record in a master table, say ORDER, then I use the key, say OrderID (auto-increment integer) when I come to insert a record in a detail table, say ORDER_LINE - The PK for order line consists of  OrderID & LineID (auto-increment) together -

a) how do I pass the id or ORDER, and

b) will it return OrderID, LineID following the insert in ORDER_LINE?

RE: Does this work?
February 8, 2001 by George Petrov
Hi, currenly the this works only for MS SQL Server 2000 and Access 2000. There you gave the system variable @@IDENTITY that contains the last inserted id.
There should be the same construction for MySQL, but I couldn't found - maybe you can help me with this. Then I will build it into the extension.
RE: How do you make use of the ident? compound keys and others
February 8, 2001 by George Petrov

Well you have a variable LastIdent, it is set in the script. You just have to switch off the redirect and put your own code that uses this variable just after the the insert script.

Maybe it will be better if I make a Session variable from this one in the next version of this extension ...

how about an error page
February 21, 2001 by sandy santos

mr. petrov,

i know this is not on your extension i was just hoping you could help. i was wondering how could i modify the insert record extension so that when a user didn't put anything on 1 field it would display an error message stating that the specific field has no entry?

thanks.

sandy

RE: how about an error page
February 21, 2001 by George Petrov
You sould insert the Validate Form behavior that will check the form before submission and report any errors to the user.
RE: RE: how about an error page
February 22, 2001 by sandy santos
where can i find the validate form?
if no redirect, how do we go from here?
February 22, 2001 by Coll Rey

Ok, if I have filled out the behaviour variables, and leave blank, "after inserting go to," (not put in a redirect page per online instructions), then how do I get to the next page so I can pull down that variable?

Also, does the form need to be submitted to itself?   And what does the cursor type need to be?

And how can I find out  more info on session variables?  Thanks.

ASP does not like this SQL
February 22, 2001 by Coll Rey

After inserting this server behaviour,  filling out all the fields (correctly?) I get the following message:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
/beta/TMPc79d296c76.asp, line 91

 

Help!

RE: if no redirect, how do we go from here?
March 9, 2001 by Andres Gibson

There is a problem giving parameters to the "after inserting go to" field. You can specify a file name, but you can't send parameters to it. Use session variables to send parameters from one page to other.

 

Pd: Cool tool for reply ... congratulations for it ... ;)

RE: ASP does not like this SQL
March 21, 2001 by ed ko
getting the same problem...so what was the fix to this
Invalid SQL statement error
March 26, 2001 by Tim Pattison

I have noticed several people have been receiving this error as well as myself. I'm using an Access 2000 DB & I've tried it on SQL 7.0.

I receive this error on BOTH types of DBs:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

Any resolution to this so far?

RE: Invalid SQL statement error
March 26, 2001 by George Petrov

Can you send me the SQL statement that gets generated? To get it add after the line:

MM_editCmd.CommandText = "...."

Add:

Response.Write MM_editCmd.CommandText
Response.End

This will output the SQL and end processing. Execute the page, copy the SQL and send it to me (via private mail please), then remove the lines from your code.

Also the problem is only with Access.
SQL Server does accept the SQL statement - whole UDzone is full with this stuff.

RE: Invalid SQL statement error
March 26, 2001 by George Petrov

Identity works with Access 2000 ONLY if you use the "Jet OLEDB Provider 4.0"!

So define your ODBC connection not with "Microsoft Access Driver" but with "Jet OLEDB Provider 4.0". So your connection string should look like:

"Provider=Microsoft.Jet.OLEDB.4.0;Data source="C":\Backup\OBS\Development\Db\obs2k.mdb;Persist Security info="False""

If you use a DSN-Less connection. Otherwise its in the ODBC Settings.

Read more about this in the following ASPWATCH article

error when I try to apply the behavior
March 27, 2001 by Daniel Morrow

I get this error from ultradev when I try to apply the behavior:

____________________________________

Server Behavior was not applied. Could not find a valid XML file that refers to the current server behavior and the current server model.

____________________________________

I'm assuming that I didn't install the behavior correctly?  All I did was double-click the download, and it seem to go through properly.

Problem
April 5, 2001 by Matt Homey
1. I don't use a redirection page 2. Here's the error: Error Type: Microsoft JET Database Engine (0x80040E14) Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'. The conn string should be fine: "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("db/db.mdb") Suggestions?
Does not work with Jet 4.0 sp5
April 11, 2001 by Chris Sullivan
I cannot seem to get this behavior to work correctly. I am using Win2k, and have double checked that I have Jet 4.0 installed. I get the same error as the post below. This behavior is great, I just wish I could get it to work.
Is there a Tutorial for this Behaviour?
June 14, 2001 by Rick Heidrick
Everything seems to be working fine - updates work, but how do I access the LastIdent Variable to write to page and use as a filter for a recorset in later pages?
Patch to make the code work with ANY driver
July 8, 2001 by Rogier Mulhuijzen

The Jet 4.0 driver was unacceptable on our project so I updated it to make it work regardless of the driver.

Here is the original piece of code:

--------

    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = "SET NOCOUNT ON;" & MM_editQuery & ";SELECT @" & "@IDENTITY AS Ident"
    Set rsLastIdent = MM_editCmd.Execute
    if NOT rsLastIdent.EOF then
        LastIdent = rsLastIdent.Fields.Item("Ident").Value
    end if
    MM_editCmd.ActiveConnection.Close
--------

And here is the new piece

--------

    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.CommandText = "SELECT @" & "@IDENTITY AS Ident"
    Set rsLastIdent = MM_editCmd.Execute
    if NOT rsLastIdent.EOF then
        LastIdent = rsLastIdent.Fields.Item("Ident").Value
    end if
    MM_editCmd.ActiveConnection.Close
-------

 

RE: Patch to make the code work with ANY driver
August 1, 2001 by Eric Kaiser

YES!!! That works really great. Thank you. But one thing, 'cause I see some people asking about this. The session variable is not set. Go to this line:

if NOT rsLastIdent.EOF then
        LastIdent = rsLastIdent.Fields.Item("Ident").Value
    end if

And change:

LastIdent = rsLastIdent.Fields.Item("Ident").Value

to

Session("LastIdent") = rsLastIdent.Fields.Item("Ident").Value

Thanks again!!!
    
   

prob after variable is set
August 28, 2001 by Chris Watson
i need to redirect on submission but every method i try fails miserably. any help?
Server behavior was not applied...
September 5, 2001 by Brian Isbrandt

I receive the following error (below) when I try applying the insert record with identity behavior. I'm running SQL 2000 and UD4 using Javascript as my server language. Any ideas?

 

--"server behavior was not applied. Could not find a valid XML file that
refers to the current server behavior and the current server model."--

Converted into JavaScript
October 5, 2001 by Andre Bender

Can somebody please translate me the code into JavaScript. Thanks!

Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.CommandText = "SELECT @" & "@IDENTITY AS Ident"
    Set rsLastIdent = MM_editCmd.Execute
    if NOT rsLastIdent.EOF then
        Session("LastIdent") = rsLastIdent.Fields.Item("Ident").Value
    end if
    MM_editCmd.ActiveConnection.Close

Insert with Ident for MySQL
October 16, 2001 by Jörg Schwalenberg

Hi All,

Many Users has ask me to this little Code Snippet for George Petrov's Extension. This work with MySQL in DSN or DSN less Connection.

..................................................................................

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.CommandText = "SELECT LAST_INSERT_ID() AS Ident"
    Set rsLastIdent = MM_editCmd.Execute
    if NOT rsLastIdent.EOF then
        Session("LastIdent") = rsLastIdent.Fields.Item("Ident").Value
    end if
    MM_editCmd.ActiveConnection.Close
...................................................................................

Good Luck !

Best Regards from Germany 

Jörg 
ultradevextensions.de

 

RE: Insert with Ident for MySQL
October 16, 2001 by George Petrov

Thanks! I was looking for this one! Now I need one for Oracle too.

Also maybe a way how to detect what database is being used now ...

Updated Extension
December 26, 2001 by Jon Streeter

Any chance of updating the extension so by default it does not requite jet4.0?

How can we install it in the first place?
February 6, 2002 by nicolas diogo
Hi everyone I still trying to create a page that retrieves the ID of last inserted record from a Database. But when I try to install the extention. The message that I receive is; --"server behavior was not applied. Could not find a valid XML file that refers to the current server behavior and the current server model."-- Thanks in advance
Confused
February 20, 2002 by Richard Davies

This extension is just what I'm looking for (I think) but I could do with a bit of help if anyone has time. First a couple of questions

1. The description of this behaviour says that it is a "Modification" of Insert Record Server Behaviour. Does this mean that it has overwritten the original Behaviour?

2. I'm using this behaviour on a ecommerce site where the users dont register. I'm planning on generating a "CustomerID" session variable first. I dont understand how this Server Behaviour will let me do this though

Rich

Error on inserting SB
April 26, 2002 by Steven Robinson

What is causing the following error?

Server behavior was not applied. Could not find a valid XML file that
refers to the current server behavior and the current server model.

I've noted that others have received this error as well but I am unable to find any responses from Tech Support, or others at UDZone, as to what the cause may be and how to work around it.

not compatible with MX
June 13, 2002 by Gert-Jan Klasens

I tried to use this extension in Dreamweaverr MX, but it

can't be used.. I got the following error message:

Javascript error while loading InsertRecordWithIdent ..

Unable to open scriptfile "/EditOperations.js"[error2]

 

Gert-Jan

RE: not compatible with MX
June 13, 2002 by George Petrov

Yes as you can see from the properties info - there is no MX support yet.

I hope to make it very soon.

MX Support?
June 17, 2002 by Magnus M

Hi George

When will you add MX support for this extension?

 

/Magnus

RE: RE: not compatible with MX
September 3, 2002 by Gert-Jan Klasens
when will the MX version come ??
MX compatible...
September 30, 2002 by Matthijs Horsman

George,

Do you have any plans to update this extenion so it will be MX compatible?

Or got anyone send me the code, so i can make it work myself, like a snippet??

Thanx in advance

Matthijs

Java error
October 4, 2002 by Stephen Kennedy
I get a java error when trying to load the extension on WinXP machine.  Suggestions?
RE: RE: not compatible with MX
November 1, 2002 by Phil Conners

Open the "InsertRecordWithIdent.htm" file for editing.  (Use the Windows "search" tool to find the actual location of the file.  Make sure to edit the file that is in the folder for the server scripting you are using.)

Change the line referencing the "EditOperations.js" file location (should be line 12 in the code) to <SCRIPT SCR="../../ServerBehaviors/Shared/EditOperations.js"></SCRIPT>.

This should correct the file reference issue.

Check this out
November 6, 2002 by Jon Streeter
how can I get the Ident value?
November 25, 2002 by Vincent Liao

how can I get the Ident value?

When I use this extention to insert record. How can I get the ident value in the next page?

Thank you for your help.

 

/Vincent

working with Pureaspupload
January 5, 2003 by Domi MAES

Is this extension compatible with PureAspUpload ? I've tried with some other extension s to retrieve the autonumber but no chance.

Best regards

Domi

 

Reference error
January 10, 2003 by Victor Terblanche
I have edited the insertrecordwithident.htm as suggested, but  now I get a reference error "initializeUI". Any suggestions?
Reference error
January 10, 2003 by Victor Terblanche
I have edited the insertrecordwithident.htm as suggested, but  now I get a reference error "initializeUI". Any suggestions?
RE: Error on inserting SB
February 7, 2003 by David Scarano
Working with MX
February 23, 2003 by Barbara ONeal

George are you going to make this behavior work with DWMX?  I used to use it all the time with UltraDev 4 but it keeps throwing errors in MX.

 

Thanks.

Java Script error
February 27, 2003 by dave butcher

After installing the new extension and then restartin MX, it failed to open. Furthermore I received a Java2 error?

RE: Java Script error
May 8, 2003 by Raj Vaswani

Check out the FAQ's link above. There is a fix in there for your problem.

Not worth the time
May 27, 2003 by Archie Miller
Wasted several hours trying to get this extension to work. Besides the standard "can't find Javascript" error, I couldn't get to work with Access 2000 db with current JET driver.
could not find a valid xml file that refers to the current server behavior
July 24, 2003 by Erik De Beugher

What is causing the following error?

Server behavior was not applied. Could not find a valid XML file that
refers to the current server behavior and the current server model.

I've noted that others have received this error as well but I am unable to find any responses from Tech Support, or others at UDZone, as to what the cause may be and how to work around it.

Dreamweaver hangs...
August 19, 2003 by James Hanifen

Hi George,

Quick Question, when i add the retrieve ident on insert then add the make the ident into a session variable, is described in FAQ for the extension it always makes my dreamweaver lock up. If I add the Session code in notepad and it will work great, but I cannot open that page up in Dreamweaver ever again.

Any idea. Basically I just need the unique Id so that I can make a command on the next page.

Jim Hanifen

AHHHHH!! HELP
September 3, 2003 by Gavin Roberts

This really bites ***. I tried using this extension as it is exactly what I need, but when I tried it came back with the dreaded Javascript error. I followed the instructions that someone had wrote about the problem, still having problems.

Now I need to know how to let a user register ( insert a record ) and then be provided with there details on another page where they can update any settings, apart from there username.

I know how to use the MM_Username session when the user log's in but when I try to create a session for when the user register's It doesn't work due to a recordset not being attached to it.

Any one...

Thank You In Advance...

Gavin Roberts
Evenyoucando.co.uk

Error when launch Beahavior
October 2, 2003 by Simone Berretti

Hi,

when I launch this Behavior, dreamweaver write this error:

---------------------------
Macromedia Dreamweaver MX 2004
---------------------------
JavaScript error while loading InsertRecordWithIdent.htm:
Unable to open script file "C:\Programmi\Macromedia\Dreamweaver MX 2004\Configuration\ServerBehaviors\EditOperations.js" (error 2).
---------------------------
OK  
---------------------------

Why? Help me if is possible...

Simone

Insert Record With Identity
October 21, 2003 by Dick Fay

I am getting the following error message:

Microsoft JET Database Engineerror '80040e14'

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

/admin/addprogram.asp, line 90

Any ideas as to the problem.

Thanks

Identity Insert - Trigger Compliant
August 15, 2004 by billy flynt

When inserting to a SQL tables where insert trigger(s) exist, the value returned by @@identity (MSSQL) will contain the most recently inserted table identity value.  If you need a specific table identity value, such as when your trigger inserts to multiple tables, use something like the following:

SELECT ident_current('InsertTableNameHere') AS Ident

Poorly written extension
November 11, 2004 by Charles Beaudry

Sorry but this is a poorly written extension. Not only did I initially get the Javascript error (which I fixed after copying and pasting a shared file to the right folder) but I then got the SQL error which I couldn't fix at all.

This extension needs an update real bad so it can work properly in MX and the latest versions of Windows server technology. Right now, it's basically useless.

Problems to use
February 12, 2005 by Carlos Pereira

Hi, I already used this extension on my old computer using Win2K_PRO + DW_MX, but now, I'm trying to use on my new computer using WinXP_PRO + DW_MX, and it-s failing. DW shows the following msg:

JavaScript error while loading IRWI: Unable to open script file "../EditOperations.js" (error 2)

What do I have to do? Thank you.

PS: DMXZone could lower the price of the extensions to brazilians...US$ is too high to us...

Excelente ferramenta
February 24, 2005 by Francis Zardoz

As facilidades que esta ferramenta pode dar ao administrados de DB são claramente visiveis, pois aumenta o controle sobre a ação direta de cada inserção em cada tela de navegação, diminui o trabalho de multiplas consultas ao DB para verificar se o registro foi realmente inserido e qual o seu valor de chave, mas precisa ser extendido para suportar MySql ou tera seu uso muito limitado

RE: Insert with Ident for MySQL
December 5, 2005 by Chris Brown

Hi,

I have tried this code snippet, but now have server errors...

I simply replaced the code from George's insert with the code below and I get nothing now :-(

http://www.sitetester.co.uk/mngt/idinsert.asp

Anyone got any clue as to how to get this thing working - its a major stumbling block for me!

Thanks,

Chris.

RE: RE: Insert with Ident for MySQL
December 5, 2005 by Chris Brown

OOPS!

Got it working now - brillaint code - thanks!

Fix
July 20, 2007 by Edwin Phillips

To retreive the ID of a new record, use the Insert Record With Identity extension then locate the following lines of code:

    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = "SET NOCOUNT ON;" & MM_editQuery & ";SELECT @" & "@IDENTITY AS Ident"
    Set rsLastIdent = MM_editCmd.Execute
    if NOT rsLastIdent.EOF then
        LastIdent = rsLastIdent.Fields.Item("Ident").Value
    end if
    MM_editCmd.ActiveConnection.Close

and replace them with:

    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.CommandText = "SELECT @" & "@IDENTITY AS Ident"
    Set rsLastIdent = MM_editCmd.Execute
    if NOT rsLastIdent.EOF then
        Session("LastIdent") = rsLastIdent.Fields.Item("Ident").Value
    end if
    MM_editCmd.ActiveConnection.Close


This code is NOT dependant on driver (as the original code works on MS SQL Server/Access 2000 with "Jet OLEDB Provider 4.0" only)

 

Installation
October 14, 2008 by Mpumi Mabanga

How do I install this extension

Would not install
November 24, 2010 by Dick Fay

on DW CS5.

 

Message that it needs ultradev.