denny911 Posted January 12, 2006 Share Posted January 12, 2006 Hello,In the table "mytbl" there's a field named "hits". I'm trying to make this piece of code below increase the value of that field by one. <% Set conn = Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("database-path.mdb"))SQL = "UPDATE mytbl SET "sql=sql & " VALUES "sql=sql & "hits ='" & hits+1 & "'"sql=sql & " WHERE ID = " & ID & ""on error resume nextconn.Execute sql, recaffectedif err<>0 then Response.Write("Error!")else Response.Write("Record Added")end if%> Below this is the code that shows the value of the field hits and it works just fine. The problem is after I refresh the page, that value is NOT increased by 1, as it is supposed to be (the ERROR message appears but database's value is displayed). It only shows the value as it is, every time I refresh the page.Any suggestions?Thanks Link to comment Share on other sites More sharing options...
bolado Posted January 12, 2006 Share Posted January 12, 2006 try: SQL = "UPDATE mytbl SET "sql=sql & " VALUES "sql=sql & "hits = hits + 1"sql=sql & " WHERE ID = " & ID & "" hope this helps... Link to comment Share on other sites More sharing options...
aspnetguy Posted January 12, 2006 Share Posted January 12, 2006 from what you provided it appears that hits is a field in your db not a variable in ASP thats whysql=sql & "hits ='" & hits+1 & "'"won't workthe solution provided by bolado should work Link to comment Share on other sites More sharing options...
denny911 Posted January 12, 2006 Author Share Posted January 12, 2006 try:SQL = "UPDATE mytbl SET "sql=sql & " VALUES "sql=sql & "hits = hits + 1"sql=sql & " WHERE ID = " & ID & "" hope this helps... <{POST_SNAPBACK}> unfortunately, this didn't help.. the ERROR message is still there..Anything else? Link to comment Share on other sites More sharing options...
bolado Posted January 12, 2006 Share Posted January 12, 2006 ...what's the error description?(try removing the line 'On Error Resume next')...are you getting a value in ID var?...the field hits has at least a number (or row)?sry, for my bad engrish... Link to comment Share on other sites More sharing options...
aspnetguy Posted January 12, 2006 Share Posted January 12, 2006 try this sql = "UPDATE mytbl SET "sql=sql & "hits = hits + 1"sql=sql & " WHERE ID = " & ID & "" You don't need VALUES in there Link to comment Share on other sites More sharing options...
bolado Posted January 12, 2006 Share Posted January 12, 2006 ouch, I didn't see that one... Link to comment Share on other sites More sharing options...
denny911 Posted January 12, 2006 Author Share Posted January 12, 2006 thank to both of you, guys--the problem was in other parts of code, but i had to use the hint from BOLADO's first post.Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now