Maison > interface Web > js tutoriel > le corps du texte

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

WBOY
Libérer: 2016-05-16 19:13:31
original
1143 Les gens l'ont consulté

静态页面读取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>

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal