SQL Server @@IDENTITY Problem

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: SQL Server @@IDENTITY Problem

    I believe the better way is to place this in a stored procedure and return
    the identity property. It will work like that.
    Return it in an output parameter or a select statement if you prefer execute
    scalar or you might even return it as a return value

    Return values and output params take a little more work--I know...

    HTH
    Shane

    "Micheal" <frooyo@sbcglobal.net> wrote in message
    news:OY0tdKrVDHA.2288@TK2MSFTNGP12.phx.gbl...
    > The below code does _not_ work! The datatype for the autoincrement value
    is
    > INT in SQL Server 2000. The strange thing is that if I use a 'decimal' it
    > works (using .NET framework 1.1)
    >
    > ---------------------------------------------------------
    > string sql = "insert into sports (name) value ('test'); select
    @@identity";
    >
    > conn.Open();
    >
    > SqlCommand cmd = new SqlCommand(sql, conn);
    > int result = (int)cmd.ExecuteScalar();
    > ----------------------------------------------------------
    >
    > Thanks in advance
    >
    >

    SStory Guest

  2. Similar Questions and Discussions

    1. I?ve got a problem writing files on the server side withFlash Media Server 2.0.2 and 2.0.3.
      Hello, I?ve got a problem writing files on the server side with Flash Media Server 2.0.2 and 2.0.3. The same code was working fine with an older...
    2. Impersonate Identity doesn't work on the server
      Hello, In my application I have to impersonate users, so I add <identity impersonate="true" /> to the Web.config file. As long as I run...
    3. machine.config process identity problem
      I'm having some trouble getting ASP.NET to run under the process identity of a domain user. I created a user in the same domain in which the...
    4. DB2 - OS390: Identity Column Problem
      I have an identity column created as 'GENERATED BY DEFAULT' 'NO CACHE' 'START WITH 1' 'INCREMENT BY 1'. My problem is that at times it skips 1000...
    5. Problem with IDENTITY and ORDER BY in a INSERT statement
      Peter, I think this is a minor bug with the SQL Server parser. I've passed it on to MS. Fortunately the workaround is simple. I'll also...
  3. #2

    Default Re: SQL Server @@IDENTITY Problem

    Absolutely. Also consider using SCOPE_IDENTITY with SS 2000 as it avoids
    problems where triggers have been assigned.

    HTH

    --
    Greg Low (MVP)
    MSDE Manager SQL Tools
    [url]www.whitebearconsulting.com[/url]

    "SStory >" <Shane_Story@online.msn.com <remove the 'online.' to send me
    mail> wrote in message news:%23x6ki2sVDHA.1620@TK2MSFTNGP12.phx.gbl...
    > I believe the better way is to place this in a stored procedure and return
    > the identity property. It will work like that.
    > Return it in an output parameter or a select statement if you prefer
    execute
    > scalar or you might even return it as a return value
    >
    > Return values and output params take a little more work--I know...
    >
    > HTH
    > Shane
    >
    > "Micheal" <frooyo@sbcglobal.net> wrote in message
    > news:OY0tdKrVDHA.2288@TK2MSFTNGP12.phx.gbl...
    > > The below code does _not_ work! The datatype for the autoincrement
    value
    > is
    > > INT in SQL Server 2000. The strange thing is that if I use a 'decimal'
    it
    > > works (using .NET framework 1.1)
    > >
    > > ---------------------------------------------------------
    > > string sql = "insert into sports (name) value ('test'); select
    > @@identity";
    > >
    > > conn.Open();
    > >
    > > SqlCommand cmd = new SqlCommand(sql, conn);
    > > int result = (int)cmd.ExecuteScalar();
    > > ----------------------------------------------------------
    > >
    > > Thanks in advance
    > >
    > >
    >
    >

    Greg Low \(MVP\) 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