B
Bon
I created a stored procedure for inserting new data to database and
then select scope_identity. The returned ID result is correct when i
run the SP directly. But, ASP recordset return a wrong result. It
always return the previous ID. For example, the current ID is 100.
After I call the SP from ASP page, SP is run and the ID is 101. But,
the ASP recordset would return 100. Any suggestion?
My SP code:
CREATE PROCEDURE sp_stored_procedure_na,e
@param1 char (10),
@param2 varchar(255)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO myTableName
(
Name,
Address
)
VALUES
(
@param1,
@param2
)
SELECT SPReturnedID = SCOPE_IDENTITY()
END
My ASP code is embedded in Javascript:
<%
Dim objrs-dr
%>
function AddRow_clk()
{
'use xmlhttp to pass parameters
....
<%
Set objrs_dr = dbconnection.execute("Exec sp_stored_procedure_name
@param1='" & Request("Name") & "',@param2='" & Request("Address") &
"'")
session("ReturnedScopeID") = objrs_dr.Fields("SPReturnedID")
%>
alert ( <%=session("ReturnedScopeID")%> );
....
}
I use Javascript to test the returned result. It always returns 100
instead of 101. Could you give me some suggestions?
Cheers
Bon
then select scope_identity. The returned ID result is correct when i
run the SP directly. But, ASP recordset return a wrong result. It
always return the previous ID. For example, the current ID is 100.
After I call the SP from ASP page, SP is run and the ID is 101. But,
the ASP recordset would return 100. Any suggestion?
My SP code:
CREATE PROCEDURE sp_stored_procedure_na,e
@param1 char (10),
@param2 varchar(255)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO myTableName
(
Name,
Address
)
VALUES
(
@param1,
@param2
)
SELECT SPReturnedID = SCOPE_IDENTITY()
END
My ASP code is embedded in Javascript:
<%
Dim objrs-dr
%>
function AddRow_clk()
{
'use xmlhttp to pass parameters
....
<%
Set objrs_dr = dbconnection.execute("Exec sp_stored_procedure_name
@param1='" & Request("Name") & "',@param2='" & Request("Address") &
"'")
session("ReturnedScopeID") = objrs_dr.Fields("SPReturnedID")
%>
alert ( <%=session("ReturnedScopeID")%> );
....
}
I use Javascript to test the returned result. It always returns 100
instead of 101. Could you give me some suggestions?
Cheers
Bon