Submit to Web Service return value for insert operation

R

Rick

I have a form that is using a web service to insert the form data into a
database. The inserted record has an auto-increment primary key value. After
the insert is performed I want to re-query the database using the primary key
of the record created during the submit process.

How do I get the primary key back to the form after submitting the form?
 
P

Paresh

I have a form that is using a web service to insert the form data into a
database. The inserted record has an auto-increment primary key value. After
the insert is performed I want to re-query the database using the primary key
of the record created during the submit process.

How do I get the primary key back to the form after submitting the form?



Hi,

One way of doing this is to write a stored procedure that performs the
insert record operation and after that stored procedure, you can
return the generated primary key value using SCOPE_IDENTITY() method
of the SQL and collect this value in your web service.

Give this a though. I guess this should help you out. Still, if you
need any further assistance, do let me know.


Thanks,
Paresh
 
P

Paresh

Hi,

One way of doing this is to write a stored procedure that performs the
insert record operation and after that stored procedure, you can
return the generated primary key value using SCOPE_IDENTITY() method
of the SQL and collect this value in your web service.

Give this a though. I guess this should help you out. Still, if you
need any further assistance, do let me know.

Thanks,
Paresh


The stored procedure can be something like this:

CREATE PROCEDURE [dbo].[usp_InsertRecord]
@Column1 int,
@Column2 int,
@Column3 int,
@PrimKeyColumn int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[Table1] (
[Column1],
[Column2],
[Column3]
) VALUES (
@Column1,
@Column2,
@Column3
)

SET @PrimKeyColumn = SCOPE_IDENTITY()

Also, you dont need to re-query the database. The web service method
that you are writing to insert the record can be modified in such a
way that the same method collects the primary key value returned by
the stored procedure after insertion.

Hope this helps.

Thanks,
Paresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top