Re: @@Identity
From: Scott M. (NoSpam_at_NoSpam.com)
Date: 09/16/04
- Next message: W.G. Ryan eMVP: "Re: Datagrid not updating after dataset records change"
- Previous message: Popezilla: "No reply to MSDN subscriber message"
- In reply to: Mary Chipman: "Re: @@Identity"
- Next in thread: William \(Bill\) Vaughn: "Re: @@Identity"
- Reply: William \(Bill\) Vaughn: "Re: @@Identity"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 16 Sep 2004 17:49:02 -0500
My question is: do I need to do something to establish the Identity column
in the first place if the data is coming from an existing database that has
a primary key already set in the db?
How does VB.NET know which column I'm talking about when I use @@Identity?
"Mary Chipman" <mchip@online.microsoft.com> wrote in message
news:m93jk09dnd46jfv1hrjpvcv19i4q1m3gbs@4ax.com...
> Unless I'm misunderstanding your use of syntax, you are confusing the
> @@Identity function with a column with the identity property set.
> @@identity is used in the case where you have just inserted a new row
> in a table that has an identity column defined and you want to
> retrieve the new identity value. All of the "@@" globals are functions
> which return some kind of information from the server. So when
> selecting from a table with an identity column you simply refer to it
> by its column name, like any other column. If you are updating the
> row, omit the identity column from the update statement (except in the
> WHERE clause, where you refer to it by its column name). For more
> information on identity columns and @@identity, see SQL Books Online.
>
> --Mary
>
> On Thu, 16 Sep 2004 00:09:37 -0500, "Scott M." <NoSpam@NoSpam.com>
> wrote:
>
>>Thanks for your reply. I am using VB.NET, not C#, so I'm not sure what
>>your
>>code snippet is designed to do. If I have a simple SELECT like "SELECT *
>>FROM foo" and "foo" already contains a primary key in the db, would that
>>field automatically be the @@Identity field when it is brought into my
>>DataSet? If not, what would I do to mark the correct column as the
>>identity
>>field?
>>
>>Thanks.
>>
>>
>>
>>"Gaurav Vaish" <mDaOsNtOeTrSgPaAuMrPaLvS.nospam@nospam.lycos.com> wrote in
>>message news:%23YGCuk6mEHA.644@tk2msftngp13.phx.gbl...
>>>> How do I set the @@Identity parameter for data that has been read in
>>>> from
>>> a
>>>> database? I have read in data via a command (SELECT statement) and am
>>>> trying to build a good UPDATE statement and want to use the @@Identity
>>>> field.
>>>
>>>
>>> Hi,
>>>
>>> Directly use the value of the identity field. I assume that you know
>>> the
>>> name of the field. For example, if you have a table like:
>>>
>>> t_sample {
>>> id as autonumber,
>>> first as varchar(50),
>>> second as int
>>> }
>>>
>>> Doing a select that includes "id" as a field will give you the
>>> @@Identity (the autonumber). You can use this (columns["id"]) value
>>> during
>>> your update command.
>>>
>>> Does this answer your question? Or, then, can you provide your SELECT
>>> and UPDATE statements? That may things more visible!
>>>
>>> --
>>>
>>> Happy Hacking,
>>> Gaurav Vaish
>>> http://www.mastergaurav.org
>>> -----------------------------------
>>>
>>>
>>
>
- Next message: W.G. Ryan eMVP: "Re: Datagrid not updating after dataset records change"
- Previous message: Popezilla: "No reply to MSDN subscriber message"
- In reply to: Mary Chipman: "Re: @@Identity"
- Next in thread: William \(Bill\) Vaughn: "Re: @@Identity"
- Reply: William \(Bill\) Vaughn: "Re: @@Identity"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|