...

View Full Version : Adding Numbers



Baleric
09-17-2005, 02:47 PM
hihi ppl, im having trouble adding numbers to a database,
i have a news page where i would like to have a hit counter.
And like every other hit counter i would like to add a +1 when someone comes in to view that news,
now here is my code.


<% Set cnnLogin = Server.CreateObject("ADODB.Connection")
cnnLogin.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
& "DBQ=" & Server.MapPath("SamDave.mdb"))
%>

<% cnnLogin.execute("UPDATE _news SET news_views = '" & 1 & "' WHERE ID = '" & request.QueryString("show") & "'") %>

i also have the database as a number instead of text, cause i was told that it should add a 1 automatically to the existing number...
appreciate any comments

thanx -baleric

oracleguy
09-17-2005, 11:26 PM
Since it is a number you do not need single quotes around it. Your query would look like:


cnnLogin.execute("UPDATE _news SET news_views = news_views + 1 WHERE ID = '" & request.QueryString("show") & "'")

You can add do the math directly in the SQL query itself.

Speedy
09-17-2005, 11:32 PM
I suggest you too change ur databas-connection to this:



<% Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("urdatabase.mdb") %>


This connection is the "new" Microsoft JET standard.. it works better.

Baleric
09-18-2005, 04:59 AM
now im copping this error .

Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
/SamDave/Pages/ShowNews.asp, line 55

this is my line 55 now.

<% cnnLogin.execute("UPDATE _news SET news_views = news_views + 1 WHERE ID = '" & request.QueryString("show") & "'") %>

thanks for hlp guys

neocool00
09-19-2005, 02:50 PM
@Baleric,
In the table you are updating, is ID a numeric value? If so, get rid of the ' before and after the request string.

...WHERE ID = " & request.QueryString("show") & ""...

glenngv
09-20-2005, 03:06 AM
This is double-posted (http://www.codingforums.com/showthread.php?t=68483) in this forum and was already answered there.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum