静态页面读取ACCESS数据库.htm
<script> <BR> //用 JavaScript 写服务器端连接数据库的代码示例 <BR> var conn = new ActiveXObject("ADODB.Connection"); <BR> conn.Open("DBQ=E:\\a.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"); <BR> var rs = new ActiveXObject("ADODB.Recordset"); <BR> var sql="select * from friends_infor"; <BR> rs.open(sql, conn); <BR> shtml = "<table width='100%' border=1>"; <BR> shtml +="<tr bgcolor='#f4f4f4'><td>au_id<td>au_lname<td>au_fname"; <BR> while(!rs.EOF) <BR> { <BR> shtml += "<tr><td>" + rs("friend_id") + "<td>" + rs("friend_name") + "<td>" + rs("friend_nickname") + ""; <BR> rs.moveNext; <BR> } <BR> shtml += ""; <BR> document.write(shtml); <BR> rs.close(); <BR> rs = null; <BR> conn.close(); <BR> conn = null; <BR> </script>
添加数据到数据库页面-Insert.htm
删除功能-Delete.htm
<script> <BR>//function deldata(userid) <BR>//{ <BR> //用 JavaScript 写服务器端连接数据库的代码示例 <BR> var conn = new ActiveXObject("ADODB.Connection"); <BR> conn.Open("DBQ=E:\\a.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"); <BR> var rs = new ActiveXObject("ADODB.Recordset"); <BR> var sql="delete from friends_infor where friend_id=135"; <BR> //rs.open(sql, conn); <BR> //rs.close(); <BR> //rs = null; <BR> conn.execute(sql); <BR> conn.close(); <BR> conn = null; <BR> alert("修改成功"); <br><br>//} <BR> </script>
修改功能 Updata.htm
<script> <BR>function getdata() <BR>{ <BR> //用 JavaScript 写服务器端连接数据库的代码示例 <BR> var conn = new ActiveXObject("ADODB.Connection"); <BR> conn.Open("DBQ=E:\\a.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"); <BR> var rs = new ActiveXObject("ADODB.Recordset"); <BR> var sql="select * from friends_infor where friend_id=100"; <BR> rs.open(sql, conn); <BR> shtml = "<table width='100%' border=1>"; <BR> shtml +="<tr bgcolor='#f4f4f4'><td>friend_id<td>friend_name<td>friend_nickname"; <BR> while(!rs.EOF) <BR> { <BR> shtml += "<tr><td>" + rs("friend_id") + "<td>" + rs("friend_name") + "<td>" + rs("friend_nickname") + ""; <BR> shtml += "<tr><td>" + rs("friend_id") + "<input name=userid id=userid type=hidden value=" + rs("friend_id") + " /><td><input name=username id=username type=text value=" + rs("friend_name") + " /><td><input name=nickname id=nickname type=text value=" + rs("friend_nickname") + " />"; <BR> rs.moveNext; <BR> } <BR> shtml += ""; <BR> document.write(shtml); <BR> rs.close(); <BR> rs = null; <BR> conn.close(); <BR> conn = null; <BR>} <BR>getdata() <BR> </script> <script> <BR>function editmdb(userid,username,nickname) <BR>{ <BR> //用 JavaScript 写服务器端连接数据库的代码示例 <BR> var conn = new ActiveXObject("ADODB.Connection"); <BR> conn.Open("DBQ=E:\\a.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"); <BR> var rs = new ActiveXObject("ADODB.Recordset"); <BR> var sql="update friends_infor set friend_name='" + username + "',friend_nickname='" + nickname + "' where friend_id=" + userid + ""; <BR> //rs.open(sql, conn); <BR> //rs.close(); <BR> //rs = null; <BR> conn.execute(sql); <BR> conn.close(); <BR> conn = null; <BR> alert("修改成功"); <BR>getdata() <BR>} <BR> </script>