数据库记录更新不了

xawnu 2009-07-13 11:18:09
ASP程序,用来统计站点访问页面,每个商家有个单独的ID(VisSmemberid )作为主键
用下面程序判断,思路是这样,如果数据库表里没有这个商家的记录就添加一个商家记录,
sitememberid这个是作为会话调用判断商家ID的

protype,shopstype ,bustype,这个几个表示商家页面主页面,产品页面,和购买页面

如果已经包含这个商家记录的话,在这条记录上更新,但是测试过后,添加可以,但是更新记录通不过
,测试将else下面的语句放到判断的上半部分的时候,可以添加没有的记录,也可以更新,但是只能更
新数据库表里的第一条记录,其他记录更新不了。






<%
dim countrs,bustype,shopstype,protype
protype = request.QueryString("protype")
shopstype = request.QueryString("shopstype")
bustype = request.QueryString("bustype")
sitememberid = request.QueryString("sitememberid")

set countrs = server.CreateObject("adodb.recordset")
countrs.open "select * from [Visitz]",conn,1,3

if VisSmemberid <> sitememberid then

countrs.addnew
countrs("VisSmemberid")=sitememberid
if session("fortunememberid") <> ""then
countrs("VisFmemberid")=session("fortunememberid")
countrs("VisType")=1 '0匿名 1会员
else
countrs("VisType")=0
end if
if bustype = 1 then
countrs("VisBus")=1
end if
if protype = 1 then
countrs("VisPro")=1
end if
if shopstype = 1 then
countrs("VisShops")=1
end if

else

if session("fortunememberid") <> ""then
countrs("VisFmemberid")=session("fortunememberid")
countrs("VisType")=1 '0匿名 1会员
else
countrs("VisType")=0
end if
if bustype = 1 then
countrs.open "select * from [Visitz] where VisSmemberid="&request("sitememberid"),conn,1,3
countrs("VisBus")=rs("VisBus")+1

countrs.update

'countrs("VisBus")=1
end if
if protype = 1 then
countrs.open "select * from [Visitz] where VisSmemberid="&request("sitememberid"),conn,1,3
countrs("VisPro")=rs("VisPro")+1

countrs.update
'countrs("VisPro")=1
end if
if shopstype = 1 then

countrs.open "select * from [Visitz] where VisSmemberid="&request("sitememberid"),conn,1,3
countrs("VisShops")=rs("VisShops")+1

countrs.update
'countrs("VisShops")=1
end if

end if


countrs("VisIP")=request.ServerVariables("REMOTE_ADDR")
countrs("VisDate")=date()
countrs.update
countrs.close
set countrs = nothing
%>
...全文
44 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChinaJiaBing 2009-07-14
  • 打赏
  • 举报
回复
到.net版块看看,语句有问题...
xawnu 2009-07-13
  • 打赏
  • 举报
回复
谢谢sdhdy
可能是我上面的判断语句有问题,帮忙帮我看下
这个问题我弄好长时间,实在搞不定,来请教高手
xawnu 2009-07-13
  • 打赏
  • 举报
回复
<%
dim countrs,bustype,shopstype,protype
protype = request.QueryString("protype")
shopstype = request.QueryString("shopstype")
bustype = request.QueryString("bustype")
set countrs = server.CreateObject("adodb.recordset")
countrs.open "select * from [Visit]",conn,1,3
countrs.addnew
countrs("VisSmemberid")=sitememberid
if session("fortunememberid") <> ""then
countrs("VisFmemberid")=session("fortunememberid")
countrs("VisType")=1 '0匿名 1会员
else
countrs("VisType")=0
end if
if bustype = 1 then
countrs("VisBus")=1
end if
if protype = 1 then
countrs("VisPro")=1
end if
if shopstype = 1 then
countrs("VisShops")=1
end if
countrs("VisIP")=request.ServerVariables("REMOTE_ADDR")
countrs("VisDate")=date()
countrs.update
countrs.close
set countrs = nothing
%>
之前程序员记录是这样单条写到数据库的,这样数据库表回越来越大,所以现在要换,对应每个商家一条记录,对商城首页和产品和订购页面进行统计,现在还是更新不了记录,我找好久没有找到原因
sdhdy 2009-07-13
  • 打赏
  • 举报
回复
--我只是给你一个思路嘛。
if bustype = 1 then
countrs.open "select * from [Visitz] where VisSmemberid="&request("sitememberid"),conn,1,3
do while not countrs.eof

countrs("VisBus")=rs("VisBus")+1

countrs.update
countrs.movenext
loop
'countrs("VisBus")=1
end if
hery2002 2009-07-13
  • 打赏
  • 举报
回复
但是只能更新数据库表里的第一条记录,其他记录更新不了。
---------------
这就说明你的判断条件和循环条件有问题啊.
仔细检查一下.
xawnu 2009-07-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sdhdy 的回复:]
countrs.open "select * from [Visitz] where VisSmemberid="&request("sitememberid"),conn,1,3
countrs("VisBus")=rs("VisBus")+1
rs从哪里来的?第一行的countrs应该为RS吧?
如果你上面的记录有多条的话,你要用一个记录集的循环的。如
do while not rs.eof
countrs("VisBus")=rs("VisBus")+1
rs.movenext
loop
[/Quote]

这个页面是用来做访问统计的,rs这个conn文件里定义过
按照这边代码设置还是更新不了

因为主要判断在VisSmemberid和sitememberid之间,请高人指导
sdhdy 2009-07-13
  • 打赏
  • 举报
回复
countrs.open "select * from [Visitz] where VisSmemberid="&request("sitememberid"),conn,1,3
countrs("VisBus")=rs("VisBus")+1
rs从哪里来的?第一行的countrs应该为RS吧?
如果你上面的记录有多条的话,你要用一个记录集的循环的。如
do while not rs.eof
countrs("VisBus")=rs("VisBus")+1
rs.movenext
loop
cqq_chen 2009-07-13
  • 打赏
  • 举报
回复
Update更新?
为什么不直接用sql语句更新呢?
lihan6415151528 2009-07-13
  • 打赏
  • 举报
回复
while not rs.eof or not rs.bof

你的限制条件呢
Tomzzu 2009-07-13
  • 打赏
  • 举报
回复
更新是按条件的, 那个条件有问题
把拼成的SQL串, 放在数据库上调试一下就知道了
jinlingoo1 2009-07-13
  • 打赏
  • 举报
回复
既然能更新一条,其它的应该也能更新,楼主检查一下.看哪里弄错了没
叶子 2009-07-13
  • 打赏
  • 举报
回复
up
claro 2009-07-13
  • 打赏
  • 举报
回复
帮顶

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧