Code _javascript tips for using JavaScript to manipulate Access databases (read-add-delete) under static pages

Source: Internet
Author: User
Static page reads an Access database. htm
Copy Code code as follows:

<script language= "JavaScript" >
code example for using JavaScript to write server-side connection databases
var conn = new ActiveXObject ("ADODB. Connection ");
Conn. Open ("Dbq=e:\\a.mdb;driver={microsoft Access DRIVER (*.mdb)};");
var rs = new ActiveXObject ("ADODB. Recordset ");
var sql= "select * from Friends_infor";
Rs.Open (SQL, conn);
shtml = "<table width= ' 100% ' border=1>";
shtml = "<tr bgcolor= ' #f4f4f4 ' ><td>au_id</td><td>au_lname</td><td>au_fname </td></tr> ";
while (!rs. EOF)
{
sHTML + + "<tr><td>" + RS ("friend_id") + "</td><td>" + RS ("Friend_name") + "</td><td> "+ RS (" Friend_nickname ") +" </td></tr> ";
Rs.movenext;
}
sHTML = "</table>";
document.write (shtml);
Rs.close ();
rs = null;
Conn.close ();
conn = null;
</script>

Add data to a database page-insert.htm
Copy Code code as follows:

<table width= ' 100% ' border=1>
<tr bgcolor= ' #f4f4f4 ' ><td>friend_name</td><td>friend_nickname</td></tr>
<tr><td><input name=username id=username type=text value= ""/></td>
<td><input name=nickname id=nickname type=text value= ""/></td></tr>

</table>

<script language= "JavaScript" >
function Editmdb (username,nickname)
{
code example for using JavaScript to write server-side connection databases
var conn = new ActiveXObject ("ADODB. Connection ");
Conn. Open ("Dbq=e:\\a.mdb;driver={microsoft Access DRIVER (*.mdb)};");
var rs = new ActiveXObject ("ADODB. Recordset ");
var sql= "insert into friends_infor (friend_name,friend_nickname) VALUES (' + username +" ', ' "+ Nickname +") ";
Rs.Open (SQL, conn);
Rs.close ();
rs = null;
Conn.execute (SQL);
Conn.close ();
conn = null;
Alert ("Add success");
}
</script>
<input name= "1" type= "button" value= "Add" onclick= "Editmdb (username.value,nickname.value)"/>

Delete Feature-delete.htm
Copy Code code as follows:

<input name= "1" type= "button" value= "Modify" onclick= ""/>
<script language= "JavaScript" >
function Deldata (userid)
//{
code example for using JavaScript to write server-side connection databases
var conn = new ActiveXObject ("ADODB. Connection ");
Conn. Open ("Dbq=e:\\a.mdb;driver={microsoft Access DRIVER (*.mdb)};");
var rs = new ActiveXObject ("ADODB. Recordset ");
var sql= "Delete from friends_infor where friend_id=135";
Rs.Open (SQL, conn);
Rs.close ();
rs = null;
Conn.execute (SQL);
Conn.close ();
conn = null;
Alert ("modified successfully");

//}
</script>

Modify Feature Updata.htm
Copy Code code as follows:

<script language= "JavaScript" >
function GetData ()
{
code example for using JavaScript to write server-side connection databases
var conn = new ActiveXObject ("ADODB. Connection ");
Conn. Open ("Dbq=e:\\a.mdb;driver={microsoft Access DRIVER (*.mdb)};");
var rs = new ActiveXObject ("ADODB. Recordset ");
var sql= "select * from Friends_infor where friend_id=100";
Rs.Open (SQL, conn);
shtml = "<table width= ' 100% ' border=1>";
shtml + <tr bgcolor= ' #f4f4f4 ' ><td>friend_id</td><td>friend_name</td><td> Friend_nickname</td></tr> ";
while (!rs. EOF)
{
sHTML + + "<tr><td>" + RS ("friend_id") + "</td><td>" + RS ("Friend_name") + "</td><td> "+ RS (" Friend_nickname ") +" </td></tr> ";
sHTML + + "<tr><td>" + RS ("friend_id") + "<input name=userid id=userid type=hidden value=" + RS ("friend_id") + "/></td><td><input name=username id=username type=text value=" + RS ("Friend_name") + "/></td& Gt;<td><input name=nickname id=nickname type=text value= "+ RS (" Friend_nickname ") +"/></td></tr& gt; ";
Rs.movenext;
}
sHTML = "</table>";
document.write (shtml);
Rs.close ();
rs = null;
Conn.close ();
conn = null;
}
GetData ()
</script>


<script language= "JavaScript" >
function Editmdb (userid,username,nickname)
{
code example for using JavaScript to write server-side connection databases
var conn = new ActiveXObject ("ADODB. Connection ");
Conn. Open ("Dbq=e:\\a.mdb;driver={microsoft Access DRIVER (*.mdb)};");
var rs = new ActiveXObject ("ADODB. Recordset ");
var sql= "Update friends_infor set friend_name= '" + username + "', Friend_nickname= '" + nickname + "' where friend_id=" + US Erid + "";
Rs.Open (SQL, conn);
Rs.close ();
rs = null;
Conn.execute (SQL);
Conn.close ();
conn = null;
Alert ("modified successfully");
GetData ()
}
</script>
<input name= "1" type= "button" value= "Modify" onclick= "Editmdb (userid.value,username.value,nickname.value)"/>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.