欢迎光临
我们一直在努力

asp实现数据记录的备份及恢复—–抛砖引玉

建站超值云服务器,限时71元/月

保存数据记录到文件中:

set fs=server.createobject("scripting.filesystemobject")

filepath=server.mappath("backup.txt")

oldfilepath=server.mappath("oldbackup.txt")

fs.deletefile oldfilepath,true

fs.movefile filepath,oldfilepath

set f=fs.opentextfile(filepath,8,true)

f.writeline rs.recordcount

f.writeline rs.fields.count

for i=1 to rs.recordcount

f.writeline i

for j=0 to rs.fields.count-1

tt=rs.fields(j)

if len(rs.fields(j)) then 对非空记录

tt=cstr(tt)

tt=replace(tt,chr(13)&chr(10),chr(35)&chr(35)) 替换记录中的换行符

end if

f.writeline rs.fields(j).name&"="&tt

next

rs.movenext

next

以下是恢复数据记录到库中:

其中用到的函数:

function rsname(str) 取字段名称

str=cstr(str)

tt=instr(1,str,"=")

rsname=left(str,tt-1)

end function

function rsvalue(str) 取字段值

str=cstr(str)

tt=instr(1,str,"=")

rsvalue=replace(mid(str,tt+1),chr(35)&chr(35),chr(13)&chr(10)) 恢复回车符

end function

function delpoint(sql) 去掉sql中最后一个","

l=len(sql)

l=l-1

sql=left(sql,l)

delpoint=sql

end function

<%

sum=f.readline

sum=cint(sum) 总记录数

fields=f.readline

fields=cint(fields)列数

dim str()

for n=1 to sum

for m=0 to fields-1

redim preserve str(m)

str(m)=f.readline

next

sql1="insert into gajjsj ("

sql2=" values ("

for m=0 to fields-1

sql1=sql1&rsname(str(m))&","

sql2=sql2&rsvalue(str(m))&","

next

sql1=delpoint(sql1)&") "

sql2=delpoint(sql2)&")"

sql=sql1&sql2

response.write "第"&n&"条记录:"&"<br>sql:"&sql&"<br><br>"

conn.execute (sql) 自定义函数执行sql

redim str(1)

next

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp实现数据记录的备份及恢复—–抛砖引玉
分享到: 更多 (0)