retrieving last record inserted using @@IDENTITY - ASPJScript

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default retrieving last record inserted using @@IDENTITY - ASPJScript

    Im triyng to retrieve the last record inserted usnig the "Insert" Server
    Behavior, in a table that have an auto-incrementig id column. Im trying this by
    requesting the SQL variable @@IDENTITY... but its returning nothing! I modified
    the Server Behavior Code like this:

    var 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 vai";
    var teste = MM_editCmd.Execute();
    MM_editCmd.ActiveConnection.Close();


    and then Im retrievind the variable teste, but I got a error because nothing
    is assigned to it at all... whats wrong?

    Fabiano Arruda Guest

  2. Similar Questions and Discussions

    1. Retrieving ID of Last Inserted Table
      Hi, I've done a search of the forums and although I've found similar questions none of them seemed to answer my question. I'm currently writing...
    2. ID of last record inserted
      Is it possible, with a MS Access database, to pull the ID of a record just inserted? I have found various threads and tutorials on various sites...
    3. Identity from inserted record
      I'm inserting a record into a SQL Server database. Once the record has been added, I need the Identity value that SQL Server created. Normally, the...
    4. mySQL / Last inserted record ID
      Hi, I'm using mySQL and wanted to get the ID of the record that I have just inserted in to the table (sentmessages). There is a function in mySQL...
    5. retrieving identity
      It's better to use SCOPE_INDENTITY( ) @@IDENTITY can give a bad answer in some situations. "Kevin Spencer" <kevin@SPAMMERSSUCKtakempis.com> a...
  3. #2

    Default Re: retrieving last record inserted using @@IDENTITY - ASP JScript

    ..Execute() returns a recordset, not a value. You have to get the value out
    of the recordset.


    "Fabiano Arruda" <webforumsuser@macromedia.com> wrote in message
    news:d4it48$lhg$1@forums.macromedia.com...
    > Im triyng to retrieve the last record inserted usnig the "Insert" Server
    > Behavior, in a table that have an auto-incrementig id column. Im trying
    > this by
    > requesting the SQL variable @@IDENTITY... but its returning nothing! I
    > modified
    > the Server Behavior Code like this:
    >
    > var 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 vai";
    > var teste = MM_editCmd.Execute();
    > MM_editCmd.ActiveConnection.Close();
    >
    >
    > and then Im retrievind the variable teste, but I got a error because
    > nothing
    > is assigned to it at all... whats wrong?
    >

    Lionstone Guest

  4. #3

    Default Re: retrieving last record inserted using @@IDENTITY -ASP JScript

    and how I supose to do that?
    Fabiano Arruda Guest

  5. #4

    Default Re: retrieving last record inserted using @@IDENTITY -ASP JScript

    To retrieve a value from a Recordset assigned to a variable, and place it into
    a Session variable, use this syntax:

    // use "b]Dim rsRecordsetName" followed by "Set" instead of "var" if using
    VBscript instead of JScript:
    var rsRecordsetName = (any statement that would return an ADODB.Recordset
    value);
    Session("sessionItem") = rsRecordsetName.Fields.Item("columnName").Value;

    On ASP Classic, the second line can be shortened to:

    Session("sessionItem") = rsRecordsetName("columnName");

    (The shortcut syntax may not work on ASP.NET.)

    Don't forget to close the Recordset when you're done with it!

    rsRecordsetName.Close();
    (if VBscript): Set rsRecordsetName = Nothing


    COMALite J of MMCC Guest

  6. #5

    Default Re: retrieving last record inserted using @@IDENTITY - ASP JScript

    Maybe you would be interested in Tom Muck's extension for ASP:
    [url]http://www.tom-muck.com/extensions/help/insertretrieve/?[/url]

    "Fabiano Arruda" <webforumsuser@macromedia.com> wrote in message
    news:d4j5mi$4g6$1@forums.macromedia.com...
    > and how I supose to do that?

    Les Matthews Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139