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