> 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
Paresh - 21 Jul 2007 09:52 GMT
> > 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
[quoted text clipped - 15 lines]
> 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