JavaScript uses ActiveXObject to access access and SQL Server databases _javascript tips

Source: Internet
Author: User
Tags access database

JS Operation Access Database

Copy Code code as follows:

<script language= "JavaScript" >
<!--
var filePath = location.href.substring (0, Location.href.indexOf ("instance 197. Connect Access database. html")); Locate the absolute path where the file is located based on the current paging file
var path = FilePath + "197.mdb";
Path = path.substring (8);
var objdbconn = new ActiveXObject ("ADODB. Connection ");
var strdsn = "Driver={microsoft Access driver (*.mdb)};d bq=" + path;
Objdbconn.open (STRDSN);
document.write ("Connect Access database successfully!<br>");
Objdbconn.close ();
-->
</SCRIPT>

Connecting to SQL Server databases

Copy Code code as follows:

<script language= "JavaScript" >
<!--
var objdbconn = new ActiveXObject ("ADODB. Connection ");
var strdsn = "Driver={sql Server}"; server= (local); Uid=sa; Pwd=111111;database=hljdatabase ";
Objdbconn.open (STRDSN);
document.write ("Database connection successful <br>");
Objdbconn.close ();
-->
</SCRIPT>

Querying database instances

Copy Code code as follows:

<script language= "JavaScript" >
<!--
var objdbconn = new ActiveXObject ("ADODB. Connection ");
var strdsn = "Driver={sql Server}"; server= (local); Uid=sa;      Pwd=111111;database=hljdatabase "; Need to modify your server address, username, password
Objdbconn.open (STRDSN);
var objRS = Objdbconn.execute ("Select * FROM table where association = 0"); Enter a local table
var fdcount = objRS. fields.count-1;
if (!objrs. EOF) {
document.write ("<table border=1><tr>");
for (Var i=0 i <= fdcount; i++)
document.write ("<td><b>" + objRS). Fields (i). Name + "</b></td>");
document.write ("</tr>");

while (!objrs. EOF) {
document.write ("<tr>");
For (i=0 i <= fdcount; i++)
document.write ("<td valign= ' top ' >" + objRS.) Fields (i). Value + "</td>");
document.write ("</tr>");
Objrs.movenext ();
}
document.write ("</table>");
}
Else
document.write ("No record in the database!<br>");
objRS. Close ();
Objdbconn.close ();
-->
</SCRIPT>

Manipulating Database instances

Copy Code code as follows:

<script language= "JavaScript" >
<!--
var objdbconn = new ActiveXObject ("ADODB. Connection ");
var strdsn = "Driver={sql Server}"; server= (local); Uid=sa;   Pwd=111111;database=hljdatabase "; Need to modify your server address, username, password
Objdbconn.open (STRDSN);
Objdbconn.execute ("UPDATE table Set association = 0"); Please write your own execution statement
document.write ("Update data successfully!<br>");
Objdbconn.close ();
-->
</SCRIPT>

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.