+ -
当前位置:首页 → 问答吧 → 如何便得文件夹中文件与数据表记录中保持一致?谢谢各位了

如何便得文件夹中文件与数据表记录中保持一致?谢谢各位了

时间:2011-10-22

来源:互联网

下面代码是读取文件夹中文件并写入数据表中
但现在存在一个问题如何确保与数据表记录中保持一致,也就是当写入数据表时,若数据表记录已经存在则不添加,否则将文件名添加到数据表中,若文件不存在而数据表中有记录则清除记录该,总之就是“文件夹中文件与数据表记录中保持一致”~!

<!-- #include file="conn.asp" -->
<!-- #include file="../yhqx.asp" -->
<%
  TruePath=Server.MapPath("htxt_bb")  
  set fso=CreateObject("Scripting.FileSystemObject")  
  Set theFolder=fso.GetFolder(TruePath)  
  i = 1  
  For Each theFile In theFolder.Files  
  'Response.write("第"&i&"个<br>")  
  Response.write(""&i&"、"&theFile.Name&"<br>")  
  i = i+1  
  Next  
  For Each theFile In theFolder.Files  
dim path
path=TheFile.Name
  sql = "insert into htxt_bb(ht_bb_1)values('"&path&"')"  
  Conn.execute(sql)  
  Next
%>

作者: qjw9004   发布时间: 2011-10-22

htnow=now
For Each theFile In theFolder.Files  
dim path
path=TheFile.Name
set rs=server.createobject("adodb.recordset")
sqltext1="select * from htxt_bb where ht_bb_1='"&path&"' "
rs.open sqltext1,conn,1,1
If rs.recordcount<=0 Then
  sql = "insert into htxt_bb(ht_bb_1,ctime)values('"&path&"','"&htnow&"')"  
  Conn.execute(sql)
else
  sql = "update htxt_bb set ctime='"&htnow&"' where ht_bb_1='"&path&"'"  
  Conn.execute(sql)
end if  
Next
sql = "delete htxt_bb where ctime<>'"&htnow&"' "  
Conn.execute(sql)

作者: cosler   发布时间: 2011-10-24

热门下载

更多