标题:循环update数据库,只能修改第一条,无错误提示.
只看楼主
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
结帖率:66.67%
 问题点数:0 回复次数:9 
循环update数据库,只能修改第一条,无错误提示.
这段代码是循环update数据库里的内容,可我发现每次只能改第一条记录.这段代码有什么问题吗,并没有出现错误提示.
    set conn=server.createobject("adodb.connection")
    set rs=server.createobject("adodb.recordset")
    constr="Provider=SQLOLEDB;Data Source=HZSQL01;Initial Catalog=HRDB;User ID=ReadWrite;Password=WriteRead"
    conn.open = constr
    rs.open "select * from Lease_equip where badge ='"&owner&"' and active=2",conn,1,1
    do while not rs.eof
        autoid = rs("autoid")
        active="select"&rs("autoid")
        comments = "test"&rs("autoid")
        active            = Cint(request.form(active))
        comments            = trim(request.form(comments))
        'response.write active
        set temprs=server.createobject("adodb.recordset")
        sql = "update Lease_equip set active = '"&active&"',comments= '" &comments & "',disabledate = '"&disabledate&"' where autoid ='" & AutoID &"'"        temprs.open sql,con,1,3
        'response.write sql
    
        temprs.close
        set temprs = nothing
        con.close
        set con = nothing
    
    rs.movenext
    Loop
    rs.close
    set rs = nothing
    conn.close
    set conn= nothing
搜索更多相关主题的帖子: 错误提示 数据库 update conn 
2008-04-22 10:23
feelingxj
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2008-4-23
得分:0 
输出一下SQL,看究竟执行了几次.另外即然只是UPDATE,为什么不直接用EXECUTE?
2008-04-23 01:28
zmhdxy
Rank: 1
等 级:新手上路
帖 子:452
专家分:0
注 册:2007-9-27
得分:0 
sql语句中 字符串要用'' 数字就不要用 这个有没有错啊

2008-04-23 11:21
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
得分:0 
输出SQL语句,完全争取.但就只执行一条记录.
2008-04-24 10:27
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
得分:0 
response.write sql的结果如下:可事实上数据库里只修改了第一条,为什么啊?
update Lease_equip set active = '3',comments= 'test13',disabledate = '2008-4-24 10:37:01' where autoid =13update Lease_equip set active = '3',comments= 'test14',disabledate = '2008-4-24 10:37:01' where autoid =14update Lease_equip set active = '3',comments= 'test16',disabledate = '2008-4-24 10:37:01' where autoid =16update Lease_equip set active = '3',comments= 'test17',disabledate = '2008-4-24 10:37:01' where autoid =17update Lease_equip set active = '3',comments= 'test18',disabledate = '2008-4-24 10:37:01' where autoid =18
2008-04-24 10:38
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
得分:0 
代码重新敲了一遍就好了,诡异的事情.
2008-04-25 10:23
fengmumei
Rank: 2
等 级:论坛游民
威 望:2
帖 子:298
专家分:14
注 册:2006-9-16
得分:0 
set conn=server.createobject("adodb.connection")
    set rs=server.createobject("adodb.recordset")
    constr="Provider=SQLOLEDB;Data Source=HZSQL01;Initial Catalog=HRDB;User ID=ReadWrite;Password=WriteRead"
    conn.open = constr
    rs.open "select * from Lease_equip where badge ='"&owner&"' and active=2",conn,1,1
    do while not rs.eof
        autoid = rs("autoid")
        active="select"&rs("autoid")
        comments = "test"&rs("autoid")
        active            = Cint(request.form(active))
        comments            = trim(request.form(comments))

       conn.execute("update Lease_equip set active = '"&active&"',comments= '" &comments & "',disabledate = '"&disabledate&"' where autoid ='" & AutoID &"'")        
      
    rs.movenext
    Loop
    rs.close
    set rs = nothing
    conn.close
    set conn= nothing

随缘不变,不变随缘
2008-04-26 16:52
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
set conn=server.createobject("adodb.connection")
    set rs=server.createobject("adodb.recordset")
    constr="Provider=SQLOLEDB;Data Source=HZSQL01;Initial Catalog=HRDB;User ID=ReadWrite;Password=WriteRead"
    conn.open = constr
    rs.open "select * from Lease_equip where badge ='"&owner&"' and active=2",conn,1,3
    do while not rs.eof
        autoid = rs("autoid")
        active="select"&rs("autoid")
        comments = "test"&rs("autoid")
        active            = Cint(request.form(active))
        comments            = trim(request.form(comments))
        rs("active")=active
        rs("comments")=comments
        rs("disabledate")=disabledate
        rs.Update
    rs.movenext
    Loop
    rs.close
    set rs = nothing
    conn.close
    set conn= nothing
用一个rs记录集就可以Update的
2008-04-27 16:02
fengmumei
Rank: 2
等 级:论坛游民
威 望:2
帖 子:298
专家分:14
注 册:2006-9-16
得分:0 
楼上说的是

随缘不变,不变随缘
2008-04-30 20:12
lele2007
Rank: 5Rank: 5
来 自:广东省深圳
等 级:职业侠客
威 望:6
帖 子:1028
专家分:305
注 册:2007-9-4
得分:0 
我来凑热闹的,但我看:  conn.open = constr   这个不知道对不对,应该是:  conn.open constr   =这个也可以?

学习编程www.
2008-05-02 12:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-210389-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.330414 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved