|
发表于 2009-12-31 16:55:25
|
显示全部楼层
n久前我把那两个文件转成access了
/******************************访问数据库****************************************/
function db(dbfile) {
var con = null;
this.connection = function() {
try {
con = new ActiveXObject("ADODB.Connection");
con.Provider = "Microsoft.Jet.OLEDB.4.0";
con.C + dbfile;
con.open;
} catch (e) {
alert(e.name + ":" + e.message);
}
}
this.getdata = function(sqlstr) {
var rs = null;
try {
rs = new ActiveXObject("ADODB.Recordset");
rs.open(sqlstr, con);
} catch (e) {
alert(e.name + ":" + e.message);
}
return rs;
}
this.update = function(sql) {
try {
con.execute(sql);
} catch (e) {
alert(e.name + ":" + e.message);
}
}
this.close = function() {
try {
if (con != null) {
con.close();
con = null;
}
} catch (e) {
alert(e.name + ":" + e.message);
}
}
}
/**从数据库中查找npc和物品**/
function findGoods(obj) {
var txt = "";
var sql = "select city,room,npcid,npcname,goods,path from npcgoods where npcname like '%"
+ obj + "%' or goods like '%" + obj + "%'";
mydb = new db("D:\\Program Files\\MUSHclient\\worlds\\pkuxkx.mdb");
mydb.connection();
var rs = mydb.getdata(sql);
if (!rs.eof) {
while (!rs.eof) {
txt += rs.Fields("city") + "|" + rs.Fields("room") + "|"
+ rs.Fields("npcid") + "|" + rs.Fields("npcname")
+ "|" + rs.Fields("goods") + "|"
+ rs.Fields("path") + "\n";
rs.moveNext;
}
}
mydb.close();
if (txt == "") {
note("没有找到!");
} else {
note(txt);
}
} |
|