|
|
|
|
保存数据记录到文件中:
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)amp;chr(10),chr(35)amp;chr(35)) '替换记录中的换行符
end if
f.writeline rs.fields(j).nameamp;=amp;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)amp;chr(35),chr(13)amp;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=sql1amp;rsname(str(m))amp;,
sql2=sql2amp;rsvalue(str(m))amp;,
next
sql1=Delpoint(sql1)amp;)
sql2=Delpoint(sql2)amp;)
sql=sql1amp;sql2
Response.Write 第amp;namp;条记录:amp;<br>sql:amp;sqlamp;<br><br>
conn.Execute (sql) '自定义函数执行sql
redim str(1)
next
%gt |
|
|