Updating Identity Column in datatable

G

Guest

I am having a problem getting SQL Server to pass back to my datatable the value that it assigns to an identity column
I am using the Update method of a dataadapter and set the command text to the name of my stored procedure. The update method passes a datatable to SQL Server. Using enterprise manager I see that SQL Server inserted the row from the datatable and assigned a new value for the identity column, however when I display the value of the identity column from my datatable after the update, the value of the identity column is still -1. Do I need to query SQL Server for the value of the identity column and then assign it to the datatable?
 
J

Joe Fallon

Yes.
Either use multiple result sets or send another query to get the value.
Use ScopeIdentity!

ADO.Net by David Sceppa is a great book.
--
Joe Fallon



Gary said:
I am having a problem getting SQL Server to pass back to my datatable the
value that it assigns to an identity column.
I am using the Update method of a dataadapter and set the command text to
the name of my stored procedure. The update method passes a datatable to SQL
Server. Using enterprise manager I see that SQL Server inserted the row from
the datatable and assigned a new value for the identity column, however when
I display the value of the identity column from my datatable after the
update, the value of the identity column is still -1. Do I need to query SQL
Server for the value of the identity column and then assign it to the
datatable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top