Link to home
Start Free TrialLog in
Avatar of oksum73
oksum73

asked on

Add 1 to a numeric field in MS SQL Server

I'm trying too add the number 1 to a numeric field in MS SQL Server with asp.

Like this:

<!--#include file="../sqlcon/db.asp" -->
<%
      newID = Request("newBlogID")

      strSQL="Select * From blog where blogID="+newID+""
      Set objRS = Server.CreateObject("ADODB.Recordset")
      objRS.Open strSQL, objCON, 3, 3
      
      IF NOT objRS.EOF THEN
      
      objRS("blogRead") = objRS("blogRead") + 1

      objRS.update
      objRS.Close

      ELSE
      
      objRS.Close
      objCON.close
      Set objCON = Nothing      

      END IF      
      
%>
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

Why not just change your sql code to

"Update blog wet blogID = blogID + 1 Where blogID = "+newID+""

If it exists, it gets updated.
oops change wet to set ;-)
What error are you getting?
Avatar of oksum73
oksum73

ASKER

like this?           PS! : It doesen't work

<!--#include file="../sqlcon/db.asp" -->
<%
      newID = Request("newBlogID")

      strSQL="Update blog set blogRead = blogRead + 1 Where blogID = "+newID+""
      
      strSQL.execute
%>
What error are you receiving? And what is the structure of table blog.
ASKER CERTIFIED SOLUTION
Avatar of flipz
flipz
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<!--#include file="../sqlcon/db.asp" -->
<%
      newID = Request("newBlogID")

      strSQL="Update blog set blogRead = blogRead + 1 Where blogID = "+newID+""
     
      objCON.execute strSQL
%>
Avatar of oksum73

ASKER

Both don't work

blogID datatype  =  int

blogRead = numeric

ASP syntax?

strSQL="Select * From blog where blogID=" & newID

OR

strSQL="Update blog set blogRead = blogRead + 1 Where blogID = " & newID

if using xDJR1875/angelIII suggestion.
Avatar of oksum73

ASKER

None of the solutions work
Any error messages to help us along??
Avatar of oksum73

ASKER

I use flash as front end so you can't see any error messages.

This used to work some time ago:

objRS("blogRead") = objRS("blogRead")+1

but not any more

This works:

objRS("blogRead") = 2

But I need to add 1 each time someone clicks the blogg post
<!--#include file="../sqlcon/db.asp" -->
<%
      newID = Request("newBlogID")

      strSQL="UDATE blog SET blogRead = blogRead + 1 where blogID=" &  newID & ""
      objCON.Execute strSQL      
      objCON.close
      Set objCON = Nothing      
     
%>


this ass-u-me's that you are opening objCON in "../sqlcon/db.asp"
I really hate to be a stickler, but that really is a very inept way of doing it......but, to each his/her own I guess...
Avatar of oksum73

ASKER

Hei kevp 75, your solution work too, so I'm going with that one, is it not wise to use Recordset so much?