SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 9th, 2001, 08:46 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
read and update problem

<i><b>Originally posted by : Peter Osney (webmaster@osneymedia.co.uk)</b></i><br />Hi <br /><br />Im trying to read a record that stores a counter, increment the counter by 1 the update the record. <br /><br />I'm doing something wrong, and get an error. What is wrong with it? code below... Regards. <br /><br /><br /><% <br /><br />'Read old hit rate <br /><br />set rs=Server.CreateObject("adodb.Recordset") <br /><br />sqlstmt= "SELECT * from tblcounter where counterid = 1" <br /><br />rs.open sqlstmt, osneydsn <br /><br />counterid = rs("counterid") <br />hitcount = rs("hitcount") <br /><br />'add 1 to hit count <br />hitcount=hitcount+1 <br /><br />rs.close <br />' clears record set <br /><br />set rs2 = server.createobject("adodb.connection") <br />rs2.open osneydsn <br />'update tblcounter <br />SQLstmt = "UPDATE tblcounter" <br />SQLstmt = SQLstmt & " SET hitcount='" & hitcount & "'" <br />'SQLstmt = SQLstmt & " hitdate='" & date() & "'" <br />SQLstmt = SQLstmt & " Where counterid = " & counterid <br />' creates sql statement to insert article information into database <br /><br />Set RS2 = rs2.execute(SQLstmt) <br /><br />rs2.close <br />' clears record set <br /><br />%>

Reply With Quote
  #2  
Old April 10th, 2001, 01:05 PM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
<i><b>Originally posted by : Tim Curtin (tcurtin@nhhartford.com)</b></i><br />It looks like you are using Access( 'tbl' naming convention).<br />You forgot rs.UPDATE<br />You need a Keyset or dynamic recordset do an AddNew, Update then read the Key field back.<br />You have to do:<br /> <br /> rs.Open sqlstmt, 2,2 'keyset or dynamic rs. not sure of constants. look up in MSDN<br /> rs("hitcount") = rs("hitcount") + 1<br /> rs.Update 'HERE<br /> response.write rs("HitCount")<br /><br /><br />------------<br />Peter Osney at 4/9/2001 6:46:28 AM<br /><br />Hi <br /><br />Im trying to read a record that stores a counter, increment the counter by 1 the update the record. <br /><br />I'm doing something wrong, and get an error. What is wrong with it? code below... Regards. <br /><br /><br /><% <br /><br />'Read old hit rate <br /><br />set rs=Server.CreateObject("adodb.Recordset") <br /><br />sqlstmt= "SELECT * from tblcounter where counterid = 1" <br /><br />rs.open sqlstmt, osneydsn <br /><br />counterid = rs("counterid") <br />hitcount = rs("hitcount") <br /><br />'add 1 to hit count <br />hitcount=hitcount+1 <br /><br />rs.close <br />' clears record set <br /><br />set rs2 = server.createobject("adodb.connection") <br />rs2.open osneydsn <br />'update tblcounter <br />SQLstmt = "UPDATE tblcounter" <br />SQLstmt = SQLstmt & " SET hitcount='" & hitcount & "'" <br />'SQLstmt = SQLstmt & " hitdate='" & date() & "'" <br />SQLstmt = SQLstmt & " Where counterid = " & counterid <br />' creates sql statement to insert article information into database <br /><br />Set RS2 = rs2.execute(SQLstmt) <br /><br />rs2.close <br />' clears record set <br /><br />%>

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > read and update problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT