asp實現資料記錄的備份及恢複-----拋磚引玉

來源:互聯網
上載者:User
儲存資料記錄到檔案中:
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
%>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.