Avatar of kkamm
kkamm
Flag 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

Visual Basic.NETMicrosoft SQL Server

Avatar of undefined
Last Comment
kkamm

8/22/2022 - Mon
jaryco

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

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
jaryco

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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.
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)...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
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.