Professional Web Applications Themes

retrieving last record inserted using IDENTITY - ASPJScript - Dreamweaver AppDev

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?...

  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. #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" <webforumsusermacromedia.com> wrote in message
    news:d4it48$lhg$1forums.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

  3. #3

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

    and how I supose to do that?
    Fabiano Arruda Guest

  4. #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

  5. #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" <webforumsusermacromedia.com> wrote in message
    news:d4j5mi$4g6$1forums.macromedia.com...
    > and how I supose to do that?

    Les Matthews Guest

Similar Threads

  1. Retrieving ID of Last Inserted Table
    By JimCu in forum Coldfusion Database Access
    Replies: 5
    Last Post: February 8th, 11:56 PM
  2. ID of last record inserted
    By DJCull in forum Coldfusion Database Access
    Replies: 9
    Last Post: August 1st, 11:24 PM
  3. Identity from inserted record
    By Millsaps in forum Dreamweaver AppDev
    Replies: 4
    Last Post: April 15th, 09:19 AM
  4. returning an inserted SQL record
    By JoeyTMann in forum Coldfusion Database Access
    Replies: 2
    Last Post: March 22nd, 04:38 PM
  5. retrieving identity
    By JoŽl in forum ASP.NET General
    Replies: 4
    Last Post: June 30th, 07:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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