[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-01-04
5
Medium Priority
?
912 Views
Last Modified: 2013-01-09
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?
0
Comment
Question by:Baub Eis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 43

Accepted Solution

by:
Eugene Z earned 600 total points
ID: 38746095
it depends to what you need:

there are several options
SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY are similar functions in that they return values inserted into IDENTITY columns.

IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the value generated for a specific table in any session and any scope. For more information, see IDENT_CURRENT.

SCOPE_IDENTITY and @@IDENTITY will return last identity values generated in any table in the current session. However, SCOPE_IDENTITY returns values inserted only within the current scope; @@IDENTITY is not limited to a specific scope.


try to use
SCOPE_IDENTITY
more with code examples (@@identity as well)
http://msdn.microsoft.com/en-us/library/aa259185(SQL.80).aspx
0
 
LVL 15

Assisted Solution

by:Aaron Shilo
Aaron Shilo earned 450 total points
ID: 38746506
hi

select scope_identity() -- your specific sessions insert

select @@identity -- the last identity used
0
 

Author Comment

by:Baub Eis
ID: 38752800
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?
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 450 total points
ID: 38757267
First page and pass it to the second page using either a session variable or some other mechanism.
0
 

Author Comment

by:Baub Eis
ID: 38758922
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

0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question