帮忙进来看下这个程序,谢谢
<%
dim conn1
dim connstr1
dim conn2
dim connstr2
dim rs2
a=0
dim abc
connstr1= "DBQ= "+server.mappath( "mdb/3609664.mdb ")+ ";DefaultDir=;DRIVER={Microsoft Access
Driver (*.mdb)}; "
set conn1=server.createobject( "ADODB.CONNECTION ")
conn1.Open connstr1
'///////////////////////////
'//////////////////////////
Set rs1=Server.CreateObject( "ADODB.RecordSet ")
sql1= "select art_title from art group by art_title having count(art_title)> 1 "
rs1.open sql1, conn1,1,3
do while not (rs1.eof or err)
abc=rs1( "art_title ")
Response.Write " <br> "&rs1( "art_title ")
rs1.movenext
'/////////////以上为判断出的重复数据库记录,成功!/////////////
connstr2= "DBQ= "+server.mappath( "mdb/3609664.mdb ")+ ";DefaultDir=;DRIVER={Microsoft Access
Driver (*.mdb)}; "
set conn2=server.createobject( "ADODB.CONNECTION ")
conn2.Open connstr2
Set rs2=Server.CreateObject( "ADODB.RecordSet ")
sql2= "SELECT * from art where art_title=abc "
rs2.open sql2, conn2,1,3
while not rs2.eof
rs2.delete
rs2.movenext
wend
'/////////////////此循环嵌套在第一个循环中,找出重复记录的所有数据并删除,但错误,请高手帮忙改下/////////
loop
rs1.close
set rs1=nothing
conn1.close
set conn1=nothing
Response.Write "ok "%>
------解决方案--------------------楼主连接是同一个数据库,所以不用建立二个connection用一个就可以。用二个Recordset就可以了。还有就是删除直接用delete from这种删除。比用re.update要好些
------解决方案-------------------- <%
dim conn
dim connstr
dim rs
a=0
dim abc
connstr= "DBQ= "+server.mappath( "mdb/3609664.mdb ")+ ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}; "
set conn=server.createobject( "ADODB.CONNECTION ")
conn.Open connstr
Set rs=Server.CreateObject( "ADODB.RecordSet ")
sql= "select art_title from art group by art_title having count(art_title)> 1 "
rs.open sql, conn,1,3
do while not (rs1.eof or err)
sql= "delete form art where art_title= ' " & rs( "art_title ") & " ' "
conn.execute sql
'/////////////以上为判断出的重复数据库记录,成功!/////////////
Response.Write " <br/> 成功删除‘标题’为 "&rs( "art_title ") & " 的文章 "
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
Response.Write "ok "
%>
这段代码只用一个Connection连接和一个RecordSet记录集,比楼主用两个Connection和两个RecordSet要节省很多服务器资源和处理速度。
------解决方案--------------------一句SQL搞定,不过效率是个问题:
Delete * From art where id not in(Select min(id) from art group by art_title)