Link to home
Start Free TrialLog in
Avatar of kkamm
kkammFlag for United States of America

asked on

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.TestTableInsertQuery
GO
 
CREATE 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

Open in new window

Avatar of jaryco
jaryco
Flag of Costa Rica image

Execute this stored procedure like you execute a query and ask for the result set.
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kkamm

ASKER

Thanks for the help.

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.
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)...
Avatar of kkamm

ASKER

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.