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 March 20th, 2007, 02:24 PM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default inserting and updating records in classic asp

Hello,

I am having trouble getting records to insert and update properly. This is not a consistent problem. It is intermittent.
The page will allow me to correctly update 2 or 3 times generally, however after that it will double up the data in the insert and update.
Here is the code I am using.

Set objConn=Server.CreateObject("ADODB.Connection")

      objConn.ConnectionString = "Provider=msdaora.1;data source=db_name;user id=user_name;password=pwd"
      objConn.Open
       Dim strRecords,objCmd
       Set objCmd = Server.CreateObject("ADODB.Command")

       Set objCmd.ActiveConnection = objConn
      objCmd.CommandText="select id from next_number_gen where table_name='part_trans'"

       Set objRS = objCmd.execute
Do While Not objRS.EOF
   response.write "show me the object: " & objRS("id")& "<BR>"
   dblTrans_ID=objRS("id")
   response.write "read next number gen: " & objRS("id") & "<BR>"
  objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing

objCmd.CommandText="update part set qty_on_hand='"& iNew_Qty &"' where part_id = '"& strPart_ID &"'"
objCmd.execute

This will create 2 new records with an incremented dblTrans_ID when it decides to fail


objCmd.CommandText="insert into part_trans(trans_id,part_id,cust_id,trans_date,tra ns_qty,trans_type,invoiced) values('" & dblTrans_ID & "', '" & strPart_ID & "', '" & strCust_ID & "',TO_DATE('" & dtTrans_Date & "','DD-MON-YYYY HH24:MI:SS'), '" & iTrans_Qty & "', '" & strTrans_Type & "', '" & strInvoiced & "')"
objCmd.execute


dblTrans_ID = Cint(dblTrans_ID) + 1

This piece of code will update the table with +2 instead of +1 when it decides to fail.

objCmd.CommandText="update next_number_gen set id = '" & dblTrans_ID & "' where table_name = 'part_trans'"
objCmd.execute


objConn.Close

Set objConn = Nothing

I thought it was refreshing the page but I inserted a session variable as a counter and it showed the page only displayed once. Writing out variable tells me the code is working everytime but examining the database shows me the error.
All help would be appreciated. Thanks.


 
Old March 20th, 2007, 06:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

is this all of the code? is there a containing loop you arent showing us? Also, your do while is a waste of processing power (assuming that there are multiple rows being returned) do a SELECT MAX(id) FROM....

This will return the highest number in the datatable aleaviating the need for you to loop through a recordset.

Both of yoru response.writes in that loop should always produce the same value since you dont call MOVENEXT until after both statements have been wrote.

Anything else you can give us to look at?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 21st, 2007, 07:40 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no loop in this program other than the one notated. The rest of the code deals with assigning variables received from a form. I continue to feel that somehow this page is refreshing but have not found a circumstance that is consistent in causing this anomaly. I originally thought that the users were submitting the form twice on occassion. However I have tested this over and over and have ruled this possibility out as it fails in my testing procedures and I did not submit the form twice. On my form submission page I use the following code to ensure that the page will timeout could this somehow cause this error?

Response.AddHeader "Refresh",CStr(CInt(Session.Timeout + 1) * 1)&";URL=session_timeout_800x600.asp"
In my testing I never allowed this to go to time out value so I have discounted it but maybe I am hasty in doing so.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting records to Oracle db from asp page jowjow Classic ASP Basics 0 April 4th, 2006 09:24 AM
inserting records in oracle from asp page jowjow Oracle ASP 0 April 4th, 2006 09:17 AM
error in deleting,updating and records in asp method Classic ASP Databases 1 May 6th, 2005 10:35 AM
updating db records using asp Version: 2000 devasi Access ASP 0 February 7th, 2005 05:25 PM
Updating database records in ASP/ADO aismail3 Classic ASP Databases 5 September 16th, 2004 11:10 PM





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