Sunday, April 6, 2008

SCOPE_IDENTITY in TableAdapters

In your .xsd file, add an Insert statement which would insert then grab the primary key for use in another table

INSERT INTO Table1 (col1, col2) VALUES (@col1, @col2);
SELECT SCOPE_IDENTITY();


Then in the Visual Studio .xsd file select that insert query and go to properties and change the ExecuteMode to Scalar

...normally calling the method YourTableAdapter.Insert(...) will return an integer equalling the number of rows effected...

source for the solution documented in this post:

http://erikaday.com/programming.html

No comments: