Re: @@Identity

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Jason L James (jason_at_no-spam.dive-master.org)
Date: 08/24/04


Date: Tue, 24 Aug 2004 12:21:46 GMT

Peter,

I managed to condense it to this:

            Dim cmdID As String = "SELECT @@IDENTITY"
            Dim cmdIdent As New SqlCeCommand(cmdID, myConn)
            LastItem = CType(cmdIdent.ExecuteScalar().ToString, Int32)

The execute scalar still returns a decimal though, and not an INT,
which the the field type in my SQL CE DB.

ANy thoughts on why that might be. I would like to remove the cast
to INT32 if I can.

Thanks,

Jason.

On Tue, 24 Aug 2004 13:51:04 +0200, "PeterB" <peter@data.se> wrote:

>I don't know why it does that. What SqlCeCommand function are you using?
>
>Try using ExecuteScalar. It is the fastes way to retrieve a single data
>value.
>
>best regards,
>
> Peter
>
>
>"Jason L James" <jason@no-spam.dive-master.org> skrev i meddelandet
>news:412b25f9.756157@news.demon.co.uk...
>> Peter,
>>
>> when I executed
>>
>> SELECT @@IDENTITY FROM tblMyTable
>>
>> it returned the same @@IDENTITY value, but it did it
>> for each row in the table. That is, if there are four rows
>> in the table then the query returns 4 rows, each with the
>> same @@IDENTITY value in them?
>>
>> Any thoughts? That's why I used SELECT TOP 1 in the query
>> so that it only returned one row.
>>
>> Thanks,
>>
>> Jason.
>>
>> On Tue, 24 Aug 2004 11:00:24 +0200, "PeterB" <peter@data.se> wrote:
>>
>> >From the books online:
>> >After an INSERT, SELECT INTO, or bulk copy statement completes,
>@@IDENTITY
>> >contains the last identity value generated by the statement. If multiple
>> >rows are inserted, generating multiple identity values, @@IDENTITY
>returns
>> >the last identity value generated.
>> >
>> >So TOP 1 wouldn't be needed, you only get a single field as result..
>> >
>> > / Peter
>> >
>> >
>> >"Jason L James" <jason@nospam.divemaster.org> skrev i meddelandet
>> >news:66kli0d1pb6k37r1nrp96dvkseg0omielh@4ax.com...
>> >> Thanks, for the info. I was struglling with the conversion from
>> >> decimal to INT32 but got there in the end. I also used
>> >>
>> >> SELECT TOP 1 @@IDENTITY FROM tableName
>> >>
>> >> so that I only got 1 value, not one for every row in the table.
>> >>
>> >> Thanks,
>> >>
>> >> Jason.
>> >>
>> >> On Mon, 23 Aug 2004 15:53:32 -0500, "mgarner1980" <mgarner@kbsi.com>
>> >> wrote:
>> >>
>> >> >here's what I've used before
>> >> >
>> >> >sqlcecmd.Connection = sqlcelocaldb
>> >> >
>> >> >sqlcecmd.CommandText = materialsql
>> >> >
>> >> >sqlcecmd.ExecuteNonQuery()
>> >> >
>> >> >gstrsql = " select distinct @@identity as newmaterialid from material"
>> >> >
>> >> >sqlcecmd.CommandText = gstrsql
>> >> >
>> >> >sqlcelocaldbdr2 = sqlcecmd.ExecuteReader(CommandBehavior.SingleRow)
>> >> >
>> >> >newidentity = sqlcelocaldbdr2.GetOrdinal("newmaterialid")
>> >> >
>> >> >While sqlcelocaldbdr2.Read()
>> >> >
>> >> >newmaterialidout = sqlcelocaldbdr2.GetValue(newidentity).ToString
>> >> >
>> >> >End While
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >"Jason L James" <jason@nospam.divemaster.org> wrote in message
>> >> >news:hk2ii095jcou1iq2bv4m7r85bp9h5loa9j@4ax.com...
>> >> >> Hi,
>> >> >>
>> >> >> does anyone know how to use @@IDENTITY with
>> >> >> SQLCE Server to return the ID of the last inserted
>> >> >> record?
>> >> >>
>> >> >> Thanks,
>> >> >>
>> >> >> Jason.
>> >> >
>> >>
>> >
>> >
>>
>
>



Relevant Pages

  • Re: cant get each record to print separately
    ... Look at the information on fellow MVP Graham Mayor's website for which Peter gave you the link. ... your macro will save me from much physical therapy. ... bit hard to tell you exactly what commands to execute, ... written will send each of those letters to the printer as a separate print ...
    (microsoft.public.word.mailmerge.fields)
  • Re: cant get each record to print separately
    ... As Peter said, do NOT add any section breaks to the mail merge main document. ... You have not told us what version of Word you are using, which makes it a bit hard to tell you exactly what commands to execute, but you must execute the merge to a new document. ... When you execute the merge to a new document, the document that appears will contains all 155 of the five page letters with each one separated by a Section Break that is inserted automatically as part of the merge execution. ... Doug Robbins - Word MVP, ...
    (microsoft.public.word.mailmerge.fields)
  • Re: the difference between binary file and ASCII file
    ... > peter wrote: ... >> how can a unix shell detect that it is not an execuable binary ... > execute some file. ... which calls execwill send it to bash. ...
    (comp.unix.shell)
  • Re: Can you write code directly in CIL ???
    ... > I highly recommend that you read up on how Garbage Collection works ... In any case even if my memory needs to be constantly checked to see if it is ... >>> Peter, ... >> take more than 1/10 second to execute, since it needs to execute every second ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using Case
    ... I can't see what the Case statement does, it looks totally redundant. ... execute the code you want? ... >> But rather odd indeed. ... HTH + Cheers - Peter ...
    (microsoft.public.word.vba.general)