Wednesday, March 21, 2012

How to use SCOPE_IDENTITY() in 4-layer architecture

I have the following stored procedure:

INSERT INTO MyTable( Value1, Value 2)

VALUES( @.Value1, @.Value2)

SELECT SCOPE_IDENTITY()

How do I put this sp in the DAL typed dataset, so I can get the Identity value in the Business Layer?

From the DAL execute a query and use cmd.ExecuteScalar() this will return the identity field...

Please specify more details if this won't help you

|||

Hi,

You can use a SqlDataAdapter to execute this stored procedure as a common SELECT query. The result set will be filled into a DataSet. And the first row, first column of the first table will be the scope identity.

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!

No comments:

Post a Comment