学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
 14 12
发新话题
打印

看看为什么不能更新数据呢?(谢谢各位已经解决)

本主题由 静夜思 于 2008-5-15 20:05 审核通过

看看为什么不能更新数据呢?(谢谢各位已经解决)

我写了个小程序,例如访问网址是[url]http://bbs.bccn.net/tc.asp?com=adsdomain[/url],如果是第一次使用该地址就记录adsdomain到数据库表tc中com字段,count字段作为记录该地址访问的次数,第一次为1.
如果第二次访问就更新1为2,以此类推。但是测试“更新数据失败”
代码如下:
tc.asp的代码
<!--#include file = pcconn.asp -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%
  com=request("com")
  sql = "select * from tc where [com]='"&com&"'"
  Set rs = Server.CreateObject("ADODB.RecordSet")
  rs.Open sql,conn,1,1
  if rs.recordcount<>0 then
    id=rs("id")
               com=rs("com")
        count=rs("count")
         ne=count+1
              
Conn.Execute("update [tc] set count='"&ne&"' where id='"&id&"'")
      rs.close   
     '-------------------------------------------------------------------------

else
   Set rs = Server.CreateObject("ADODB.RecordSet")
  conn.Execute "insert into [tc] ([com]) values('"&com &"')"
      Response.Write("第一次访问记录")
end if

%>
</body>
</html>
<%
conn.close
set conn=nothing
%>

pcconn.asp 的代码
<%
set conn=Server.CreateObject("Adodb.Connection")
DBPath = Server.MapPath("pc.mdb")   'data.mdb为数据库文件名,datamdb/为路径,这两个要个数据库的文件名和路径保持一致!
conn.open "provider=Microsoft.Jet.oledb.4.0;data source="&DBpath
%>
数据库pc.mdb结构表名:tc
字段:id ,com,pccount
出错提示
错误类型:
Microsoft JET Database Engine (0x80040E14)
UPDATE 语句的语法错误。
/asptest/id2.asp, 第 26 行
错误行代码:
Conn.Execute("update [tc] set count='"&ne&"' where id='"&id&"'")

[ 本帖最后由 adsdomain 于 2008-5-21 18:55 编辑 ]

[ 本帖最后由 adsdomain 于 2008-5-28 20:30 编辑 ]

TOP

if rs.recordcount<>0 then
               id=rs("id")
               com=rs("com")
               count=rs("count")
               ne=count+1
              
               Conn.Execute("update [tc] set count='"&ne&"' where id='"&id&"'")
                rs.close
我看了还真的无语啊!   楼下你说呢!
count 是关键字!

[ 本帖最后由 不夜星空 于 2008-5-15 22:06 编辑 ]

TOP

我是楼下,但我不知道! 哈哈!开个玩笑
学建网站:www.lele1988.cn

TOP

出错提示
错误类型:
Microsoft JET Database Engine (0x80040E14)
UPDATE 语句的语法错误。
/asptest/id2.asp, 第 26 行
请看清除错误位置。发错误位置的代码/

TOP

Conn.Execute("update [tc] set count='"&ne&"' where id='"&id&"'")

count id 字段是什么类型数据
改变一切,须从改变观念开始!

TOP

清除错误位置后可以运行啊,就是每次访问都添加一个记录,count是数字id是自动编号的,count如果因为关键字不能使用但是我也看到其他程序也在使用这个也没有什么问题啊?请教各位了.

TOP

已经把count替换了,但是现实数据类型不匹配,是怎么解释啊?请教各位大侠了

TOP

Conn.Execute("update [tc] set count='"&ne&"' where id='"&id&"'")
使用rs自身的方法更新可以减少一些SQL语句错误
set rsUpdate=Server.CreateObject("ADODB.RecordSet")
rsUpdate.Open "select * from [tc] where id='"&id&"'",conn,1,3
if not rsUpdate.EOF Then
   rsUpdate("count")=ne
   rsUpdate.update
Else
   Response.Write "没有找到要更新的记录"
End IF
http://www.lxzhcn.net
版块版主招募中
网站论坛发帖无问题,欢迎发帖。

TOP

Conn.Execute("update [tc] set [count]='"&ne&"' where id='"&id&"'")
count应该是SQL的关键字,作为字段使用的时候需要加[]

TOP

谢谢yms123,替换后显示数据类型不匹配.这是什么意思啊》?

TOP

 14 12
发新话题