This topic is locked

'On Server 'function to run Stored Procedure

5/28/2010 2:32:48 PM
ASPRunnerPro General questions
B
beachldy author

I've added a button to the VIEW page and this is the code behind it (On Server section).

Code passes syntax checking, and appears to be ok. However, I'm not sure the code will work.

What I'm trying to do is run a stored procedure in sql(which copies a master table and detail tables with NEW ID's)

, then verify it copied, and then redirect user to VIEW page with the NEW id.
=======================

Function OnServer(params,result,keys)

'Get Current Tmt Plan ID to copy and pass to Stored Procedure

Dim CurTmtPlanID

CurTmtPlanID = Request.form("TmtPlanID")
'Execute SP which copies master and detail records and assigns new TmtPlanID

dbConnection.Execute "exec SP_CopyTmtPlanSTEPONETEST " & CurTmtPlanID
'check if the logging table recorded the successful inserts (and shows old and new tmt plan id's)

Dim NewTmtPlanID

Set rs = dal.Table("LOG_TmtPlansCopied").Query("OldTmtPlanID = " & CurTmtPlanID & " and DateChanged = GetDate() ")

with rs

'If not copied, display error message

If rs.recordcount <> 0 then

Response.write "Tmt Plan was not copied."

Else:

'If copied successfully, redirect user to the VIEW page with the new TmtPlanID

NewTmtPlanID = rs("NewTmtPlanID")

Response.Write "You successfully copied "& OldTmtPlanID & " to " & NewTmtPlanID

Response.Redirect "dbo_RBHS_TmtPlanHDR_4a_View.asp?TmtPlanID=" & NewTmtPlanID
End If

End with

rs.close
End Function ' OnServer

B
beachldy author 5/28/2010

The reason I need to run the SP instead of just using the COPY feature from the Master form, is because I have 3 levels of DETAIL tables which have counters as Key index fields and cannot be updated using the COPY feature on the form.