Typed dataset INSERT command return value: data row or boolean result of insertion?
This is an extension of a previously answered question. I thought I had the solution, but got sidetracked on return values.
I am trying to get the value of the unique identifier(autogenerated) for newly inserted rows so that I can update memory-resident collections to reflect the newly inserted identity value.
I am using typed datasets and I set up an insert command that contains code to return the newly inserted row via SCOPE IDENTITY. (See code window)
The problem I am having is that the command seems to be returning a numeric value, indicating the success of the operation, and not a row containing the field values I need.
If this does return a row, where can it be referenced?
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'TestTableInsertQuery' AND user_name(uid) = 'dbo') DROP PROCEDURE dbo.TestTableInsertQueryGOCREATE PROCEDURE dbo.TestTableInsertQuery( @PatID int, @Comments text)AS SET NOCOUNT OFF;INSERT INTO TestTable (PatID, Comments)VALUES (@PatID,@Comments);SELECT UniqueID, PatID, Comments FROM TestTable WHERE (UniqueID = SCOPE_IDENTITY())GO
I confirmed the functionality of the stored procedure via Query Analyzer and it worked fine. I then looked at the configuration for the dataset query, and it was set up to return nothing. I reconfigured it to return tabular data and got the identity row back.
If you don't mind, I would like to leave this question open for a little while longer while I incorporate this into my application. If I run into any issues, I may need further assistance.
Mark Wills
OK with me, though bear in mind that the next step of populating your screen is likely to be quite a different problem, and might benefit more from new zones other than SQL (but do not change this one)...
I think that the stored procedure issue is pretty solid. The rest is fodder for another question. As soon as you add identity values into the mix, disconnected datasets and collections become a little problematic.