Link to home
Start Free TrialLog in
Avatar of Baub Eis
Baub EisFlag for United States of America

asked on

How to retrieve Unique ID after record insertion / dreamweaver cs6 / Micrsoft SQL server

I am adding a page using .asp and dreamweaver cs6.  the first page loads information and the second page will be a photo upload page, but must know the identity of the record just inserted.  I used to have an extension that did this (Tom Mucks) that would load the Id into a session variable.  That extension doesn't work now in Dreamweaver CS6.  I'm looking for the best way to do this.  I know its with @@identity, but not really sure how to use it?
ASKER CERTIFIED SOLUTION
Avatar of EugeneZ
EugeneZ
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Baub Eis

ASKER

Ok I have two pages.

1st page adds basic info
2nd page adds photo

Do I use the scope_identity() on the first page and put into session variable?  Or do I put it on the second page in the SQL statement?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok I think I can pass it to the second page with a session variable, but not sure how to implement it into the default dreamweaver code.  I didn't used to have a problem, but then they rewrote they way they handle querys etc due to SQL injection attacks.  Here is just a blank page that inserts into one column:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/durgorama.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_durgorama_STRING
    MM_editCmd.CommandText = "INSERT INTO dbo.baubscope (scopebaub) VALUES (?)" 
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("scopebaub")) ' adVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "scopetest2.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>
<%
Dim baubscope
Dim baubscope_cmd
Dim baubscope_numRows

Set baubscope_cmd = Server.CreateObject ("ADODB.Command")
baubscope_cmd.ActiveConnection = MM_durgorama_STRING
baubscope_cmd.CommandText = "SELECT * FROM dbo.baubscope" 
baubscope_cmd.Prepared = true

Set baubscope = baubscope_cmd.Execute
baubscope_numRows = 0
%>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/DetailPage16grid.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="UTF-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>GlobalBizBuySell</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="Styles/960grid/960_16_col.css" />
<link rel="stylesheet" type="text/css" href="Styles/960grid/reset.css" />
<link rel="stylesheet" type="text/css" href="Styles/960grid/text.css" />
<link href="Styles/960grid/baub.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<div id="header" class="container_16 clearfix">
  <div class="grid_16"><img src="images/top_header_temp.jpg" width="940" height="50" usemap="#Map">
    <map name="Map">
      <area shape="rect" coords="526,29,574,48" href="default2.asp">
      <area shape="rect" coords="886,29,934,50" href="admin.asp">
      <area shape="rect" coords="581,29,704,48" href="buyabusiness.asp">
      <area shape="rect" coords="712,28,839,47" href="Sellabusiness.asp">
    </map>
  <img src="images/bottom_footer.jpg" width="940" height="45">  </div>
</div>
<div id="content" class="container_16 clearfix">
  <div class="grid_12"><!-- InstanceBeginEditable name="MainContent" -->
    <form name="form1" method="POST" action="<%=MM_editAction%>">
      <input type="text" name="scopebaub" id="scopebaub">
      <input type="submit" name="button" id="button" value="Submit">
      <input type="hidden" name="MM_insert" value="form1">
    </form>
  <!-- InstanceEndEditable --></div>
  <div class="grid_4"><!-- InstanceBeginEditable name="SidebarContent" -->SidebarContent<!-- InstanceEndEditable --></div>
</div>
<div id="footer" class="container_16 clearfix">
  <div class="grid_16"><img src="images/bottom_footer.jpg" width="940" height="45"><br>
    GLOBALBIZBUYSELL.COM | (636) 
 &nbsp;497 - 5597 </div>
</div>
</body>
<!-- InstanceEnd --></html>
<%
baubscope.Close()
Set baubscope = Nothing
%>

Open in new window