formview insert identity?

G

Guest

I'm trying to retrieve the @@identity value of the just-inserted record using
a FormView control on an .aspx page. Here's what I have tried.....
--change in-line Insert in the SqlDataSource from Text to Stored Procedure
--added Insert parameter "AdrID" direction:eek:utput to the SqlDataSource
--added "AdrId" as an OUT parameter in the Stored Procedure
--try to retrieve the "AdrId" in the Inserted Event handler of the
SqlDataSource

The new record is successfully inserted, but I'm still getting an error:
"An SqlParameter with ParameterName '@AdrID' is not contained by this
SqlParameterCollection."

Relevant coding:

from MaintAdrDetail.aspx....

<asp:SqlDataSource ID="AdrDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LWIF_SQLConnectionString %>"
InsertCommand="AdrInsert" InsertCommandType="StoredProcedure"
OldValuesParameterFormatString="original_{0}"
<InsertParameters>
<asp:parameter Name="@AdrID" Type=Int32 Direction=Output />
</InsertParameters>

from AdrInsert stored procedure....

ALTER PROCEDURE dbo.AdrInsert

@AdrFirstName nvarchar(25),
@AdrLastName nvarchar(50),
[clip]
@AdrOwnerID nvarchar(4),
@AdrNote nvarchar(MAX),
@AdrID int=0 OUTPUT
AS
INSERT INTO Addresses
(
[AdrFirstName],
[AdrLastName],
[clip]
[AdrOwnerID],
[AdrNote]
)
VALUES
(
@AdrFirstName,
@AdrLastName,
[clip]
@AdrOwnerID,
@AdrNote
);
SELECT @AdrID = @@IDENTITY

From MainAdrDetail.aspx.vb

Protected Sub AdrDataSource_Inserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
AdrDataSource.Inserted
Session("AdrSelected") =
e.Command.Parameters("@AdrID").Value.ToString()
End Sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top