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
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
arameter 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
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
--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
</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