Heim  >  Artikel  >  Web-Frontend  >  静态页面下用javascript操作ACCESS数据库(读增改删)的代码_javascript技巧

静态页面下用javascript操作ACCESS数据库(读增改删)的代码_javascript技巧

WBOY
WBOYOriginal
2016-05-16 19:13:311144Durchsuche

静态页面读取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
复制代码 代码如下:


 



friend_name friend_nickname


 <script> <BR> function editmdb(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="insert into friends_infor(friend_name,friend_nickname) values('" + username + "','" + nickname + "')"; <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> </script>


删除功能-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>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn