//連接SQL
復制代碼 代碼如下:
<script language="javascript">
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=tgf; User ID=sa; "
+"Password=sasa; Initial Catalog=MyBulletin");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select id,name from Category";
rs.open(sql, conn);
alert(rs(0));//取出第一個來
rs.close();
rs = null;
conn.close();
conn = null;
</script>
//連接ACCESS
復制代碼 代碼如下:
<script language="javascript">
function conn(){
var db_bbs
db_bbs="dd.mdb"//定義數據庫
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db_bbs+"");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select name from authors"; //數據庫中有authors表,name字段
rs.open(sql,conn);
alert(rs(0))//取出第一個來
conn.close();
conn = null;
}
</script>