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
%>
Like this:
<!--#include file="../sqlcon/db.asp" -->
<%
newID = Request("newBlogID")
strSQL="Select * From blog where blogID="+newID+""
Set objRS = Server.CreateObject("ADODB
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
%>
oops change wet to set ;-)
What error are you getting?
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
%>
<!--#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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<!--#include file="../sqlcon/db.asp" -->
<%
newID = Request("newBlogID")
strSQL="Update blog set blogRead = blogRead + 1 Where blogID = "+newID+""
objCON.execute strSQL
%>
<%
newID = Request("newBlogID")
strSQL="Update blog set blogRead = blogRead + 1 Where blogID = "+newID+""
objCON.execute strSQL
%>
ASKER
Both don't work
blogID datatype = int
blogRead = numeric
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.
strSQL="Select * From blog where blogID=" & newID
OR
strSQL="Update blog set blogRead = blogRead + 1 Where blogID = " & newID
if using xDJR1875/angelIII suggestion.
ASKER
None of the solutions work
Any error messages to help us along??
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
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"
<%
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...
ASKER
Hei kevp 75, your solution work too, so I'm going with that one, is it not wise to use Recordset so much?
"Update blog wet blogID = blogID + 1 Where blogID = "+newID+""
If it exists, it gets updated.