Skip to main content
Participant
November 1, 2006
質問

Write url query string of a new identity on a body msg and e-mail it.

  • November 1, 2006
  • 返信数 1.
  • 277 ビュー
How to write the URL Query String, with de new identity, in a message after insert a record?
I´m using DW 8.0.2 with ASP/VBScript and SQL Server 2000.
このトピックへの返信は締め切られました。

返信数 1

Participant
November 3, 2006
I assume you are asking how to grab the ID of the new record to use on another page..?

If so you can use a stored procedure in SQL server to insert the record and grab the ID then on the page set a variable to Session to that ID so it can be used on the following page etc.

Example

In SQL server create a Stored Procedure to carry out the INsert

CREATE PROCEDURE spInsertReport

@VarName varchar(10),
@varName2 varchar(2)

AS

SET NOCOUNT ON

INSERT INTO tablename(column1, column2) VALUES(@varName, @varName2) SELECT SCOPE_IDENTITY()

Return SCOPE_IDENTITY()

SET NOCOUNT OFF
GO

Then on the asp page of the insert replace your Insert script with a Stored Procedure call, this is in the Server behaviour drops down called Command.

<%

Dim Cmdnewrecord__varName
Cmdnewrecord__varName = "-1"
if(Request("varName") <> "") then Cmdnewrecord__varName = Request("varName")

Dim Cmdnewrecord__varName2
Cmdnewrecord__varName2 = "-1"
if(Request("varName2") <> "") then Cmdnewrecord__varName2 = Request("varName2")

%>
<%

set Cmdnewrecord = Server.CreateObject("ADODB.Command")
Cmdnewrecord.ActiveConnection = MM_example_STRING
Cmdnewrecord.CommandText = "dbo.spInsertReport"
Cmdnewrecord.Parameters.Append Cmdnewrecord.CreateParameter("@RETURN_VALUE", 3, 4)
Cmdnewrecord.Parameters.Append Cmdnewrecord.CreateParameter("@varName", 200, 1,10,Cmdnewrecord__varName)
Cmdnewrecord.Parameters.Append Cmdnewrecord.CreateParameter("@varName2", 200, 1,2,Cmdnewrecord__varName2)
Cmdnewrecord.CommandType = 4
Cmdnewrecord.CommandTimeout = 0
Cmdnewrecord.Prepared = true
Cmdnewrecord.Execute()

%>
<% Session("varNameID") = Cmdnewrecord.Parameters.Item("@RETURN_VALUE").Value %>

This example inserts the new details and grabs the ID and then sets a Session to the value, you can set any value, a varible to pass in the URL on a Response.Redirect if you wish.

If you are not sure about using a Stored Procedure or want to use the inbuilt Insert, you can use another version which is less efficient, but neverless still works

Comment out the following 2 lines of the INSERT behaviour

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
' MM_editCmd.ActiveConnection.Close <!--comment this line out -->

If (MM_editRedirectUrl <> "") Then
' Response.Redirect(MM_editRedirectUrl) <!--comment this line out -->
End If
End If

End If
%>

<%
If (CStr(Request("MM_insert")) <> "") Then <!-- if normal insert -->
If (CStr(UploadFormRequest("MM_insert")) <> "") Then <!-- if using asp uploader on page -->
set recordsetname = Server.CreateObject("ADODB.Recordset")
recordsetname.ActiveConnection = MM_editCmd.ActiveConnection
recordsetname.Source = "SELECT @@IDENTITY as MaxID FROM table" <!--change table to the name of the table -->
recordsetname.CursorType = 0
recordsetname.CursorLocation = 2
recordsetname.LockType = 3
recordsetname.Open()
Session("LatestID")=recordsetname("MaxID")
Response.Redirect(MM_editRedirectUrl)
end if
%>

ID is the name of the column you use for the records ID, change as required, also change "recordsetname" to the name of the whatever you want to call this recordset, obviously making sure it does not duplicate any recordset used on the page.

This latter example I am pretty certain I found on Charon.co.uk



quote:

Originally posted by: e.bar
How to write the URL Query String, with de new identity, in a message after insert a record?
I´m using DW 8.0.2 with ASP/VBScript and SQL Server 2000.