Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2003, 03:51 PM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Persisted Recordset Updates

I am having difficulty getting a persisted recordset update to occur. I am using an asp page to provide a recordset to a dso and am databinding the fields to input tags to allow updates. But when I use the updatebatch method I am getting an error cannot 'update identity column'. I am trying to hide the connection details from the user.

Can anyone help?


<%
    response.expires=0
    response.ContentType = "text/xml"
    response.Buffer = False

    Dim conn
    Dim rst

    strSQL = "select fullname,email,role,nas_analyst_phone,userID,statu s from tblNASAnalyst where role='ANALYST' and userid='E038924'"

    Set conn = Server.CreateObject("ADODB.Connection")
    'conn.Open "driver=sql server;server=cmhnt156.dc.bankone.net;uid=enriquem ;pwd=del1cor;database=NAS"
    conn.open "Provider=sqloledb;Data Source=SQLServer7;Initial Catalog=myDb;User id=myID;password=myPWD;"
    set rst = Server.CreateObject("ADODB.Recordset")

    rst.CursorLocation=adUseClient
    rst.Open strSQL, conn, adOpenKeySet, adLockBatchOptimistic, adCmdText
      rst.ActiveConnection= nothing

    'Instantiate an ADO Stream object to persist the recordset in
    'XML format.

    'Dim objStream
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Mode = 3 ' Read/Write mode
    objStream.Open

    response.Write "<?xml version='1.0'?>" & vbLF

    'Persist the recordset in XML format to the ADO stream object.
    rst.Save objStream, adPersistXML

    'Reposition stream pointer to the beginning of the stream, and
    'return its contents to the client using the Write method
    'of the ASP Response object.

    objStream.Position = 0
    response.write objStream.ReadText

    rst.Close
    Set rst = Nothing

%>

<object classid="clsid:BD96C556-65A3-11D0-983A-00C04fC29E33" ID="dsoNASAnalyst" width="5" height="5">
    <param name="URL" value="datapage.asp" />
</object>

<table datasrc='#dsoNASAnalyst'><tr><td><input datafld='status'><input></td></tr>

<input type="button" value="SAVE" onclick="updateStatus()"></input>

<script language="JavaScript">
<!--
function updateStatus()
{
var stmData = new ActiveXObject("ADODB.STREAM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")

dsoNASAnalyst.recordset.save (stmData, 1)

xmlhttp.open ("POST", "POSTXML.asp", false)

xmlhttp.send (stmData.readText())
alert (xmlhttp.responseText)
}
//-->
</script>


<%
response.expires = 0

set xmlDOM=server.createobject("Microsoft.XMLDOM")
xmlDOM.load (request)

set stmData=server.createobject("ADODB.Stream")

stmData.open
stmData.WriteText xmlDom.xml
stmData.setEOS

stmData.position=0

set rstData=server.createobject("ADODB.Recordset")
'rstData.CursorLocation=adUseClient

rstData.open stmData ', , adOpenKeySet, adLockBatchOptimistic, adCmdFile
set stmData=Nothing

rstData.ActiveConnection="Provider=sqloledb;Data Source=SQLServer7;Initial Catalog=mydb;User id=myid;password=mypwd;"

rstdata.updateBatch

rstData.close

set rstData= Nothing

%>


 
Old November 3rd, 2003, 03:17 PM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can not update an identity column in a sql server database. Identity columns (autonumber in access) are columns whose value is automatically generated by the database. It's used a lot for primary keys to automatically generate a new and unique value each time. You can't update that column unless you use, in SQL, the code

SET IDENTITY_INSERT table_name ON
   INSERT STATEMENT
SET IDENTITY_INSERT table_name OFF

Updating an primary key column is not a good idea though, as it must always be a unique value.

Let me know if you need any more info!

T






Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
Updates? GeekyMonkey BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 12 May 24th, 2006 12:11 PM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
What happens if someone else updates the data jaideepc ADO.NET 2 August 11th, 2004 12:02 PM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.