access| Data | database
File composition:
The Access database is named Mydata.mdb, and a table named Count is built inside the table, which consists of two
Field consists of: ID and Count, and a table with data: (' count ', ' 100 ').
The text file is named Count.txt, and a number is written inside.
The static page name is cnt.htm.
All 3 files are placed in the same directory.
Because it takes an Access database and it takes a non-standard SQL syntax, be aware that the table name
and field names need to be added square brackets: []
Here is the code in the page:
Where the Getcountfromdb method is to manipulate the Access database, Getcountfromtxt
The method is to operate on txt plain text, both of which are executed locally.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<script language= "JavaScript" >
<!--
function Getcountfromdb () {
Based on the current paging file, locate the absolute path where the file is located.
var filePath = location.href.substring (0, Location.href.indexOf ("cnt.htm"));
var path = FilePath + "Mydata.mdb";
Remove the 8 characters from the first "files://" in the string.
Path = path.substring (8);
var updatecnt = 0;
The SQL statement that is used to generate the query and update.
var sqlselcnt = "SELECT count from [Count] WHERE ID = ' count '";
var sqlupdcnt = "UPDATE [Count] SET [count] = '";
Establishes the connection and generates the associated string www.zhangpeng.com.cn.
var con = new ActiveXObject ("ADODB.") Connection ");
Con. Provider = "Microsoft.Jet.OLEDB.4.0";
Con. ConnectionString = "Data source=" + path;
Con.open;
var rs = new ActiveXObject ("ADODB. Recordset ");
Rs.Open (sqlselcnt, con);
while (!rs.eof) {
var cnt = Rs. Fields ("COUNT");
document.write (CNT);
The database will be updated after the results are obtained plus 1.
UPDATECNT = CNT * 1 + 1;
Rs.movenext;
}
Rs.close ();
rs = null;
sqlupdcnt = sqlupdcnt + updatecnt + "'";
Con.execute (SQLUPDCNT);
Con.close ();
con = null;
}
function Getcountfromtxt () {
var filePath = location.href.substring (0, Location.href.indexOf ("cnt.htm"));
var path = FilePath + "Count.txt";
Path = path.substring (8);
var nextcnt = 0;
Var fso, F1, TS, s;
Open the text file as read-only.
var ForReading = 1;
Open the text file in read-write mode.
var forwriting = 2;
FSO = new ActiveXObject ("Scripting.FileSystemObject");
F1 = fso. GetFile (path);
TS = F1. OpenAsTextStream (ForReading, true);
s = ts. ReadLine ();
nextcnt = eval (s) + 1;
document.write ("Now count is:" + s);
Ts. Close ();
TS = F1. OpenAsTextStream (ForWriting, true);
Ts. WriteLine (NEXTCNT);
Ts.close ();
}
-->
</SCRIPT>
</HEAD>
<BODY>
<script language= "JavaScript" >
<!--
Getcountfromtxt ();
-->
</SCRIPT>
</BODY>
</HTML>