<span>
来源<input type=file name=sfile>
<input type=button value=导入 onClick="splitData()">
</span>
<script>
var dbpath = location.href.replace(/file:[/]+([A-Z]:.*[/])([^/]+)/,"$1");
function connect(db_name) {
var dbc = new ActiveXObject("ADODB.Connection");
var dbcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +db_name;
dbc.Open(dbcon);
return dbc;
}
function query(sql) {
var conn = connect(dbpath+".netBook.mdb"); // 连接数据库
conn.Execute(sql);
conn.Close();
}
function splitData() {
name = document.all.sfile.value;
moveData(name,dbpath+"netBook.mdb","");
query("update data set cote=0 where cote not in (select id from itemlist)");
}
function addslashes(s) {
return s.replace(/@#/g,"@#@#");
}
// 复制db1的数据到db2
function moveData(db1,db2,exrp) {
if(! exrp) exrp = "";
conn1 = connect(db1);
conn2 = connect(db2);
rs = conn1.Execute("select * from data "+exrp);
while(!rs.EOF) {
conn2.Execute("insert into data values ("+rs("id").value
+","+rs("cote").value
+",@#"+rs("author").value+"@#"
+",@#"+addslashes(rs("title").value)+"@#"
+",@#"+addslashes(rs("content").value)+"@#"
+",@#"+rs("type").value+"@#"
+",@#"+rs("soruce").value+"@#"
+")");
rs.MoveNext();
}
rs.Close();
conn1.Close();
conn2.Close();
}
</script>
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/