"Jacek Jurkowski" <jj********@datacomp.szczecin.pl> wrote in message
news:Oc**************@TK2MSFTNGP14.phx.gbl...
My application is using an identity field of an SQL Server.
Identity field called "ID" is a Primary Key too. The problem
is when i add some record to the table SQL Server is
assigning it sime new id. But thouse is not returned into a
Data Table so the id number on SQL Server is not equal
thouse in the data table. So when I'm trying for exemple
delete row, it causes an error because UPDATE command
cannot find an ID on the SQL Server equal to the DataSet Table.
Close and re open table solves that problem but is not acceptable
for performance goals ...
How to make DataSet Table to retrieve id from the SQL Server
after insert command?
Are you using a data adapter? If so just change your INSERT statement to
look like this:
INSERT INTO customers(name, addr, city, state, zip) VALUES(@name, @addr,
@city, @state, @zip) ; SELECT id, name, addr, city, state, zip FROM
customers WHERE id = @@IDENTITY
Similarly, for the UPDATE statement, you should do something like:
UPDATE customers SET name = @name, ... WHERE id = @id ; SELECT id, name,
addr, city, state, zip FROM customers WHERE id = @id
This will catch any timestamp or similar columns that sql might have updated
but your app otherwise wouldn't know about.
HTH,
Mike Rodriguez