You know that javascript is a client-side programming language. But if you want to use the local database like MS-Access in your HTML page just using javascript? Here is some code that help you access the data of MS-Access DB in HTML page using JavaScript:
Adding a Record
function AddRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='/\dbName.mdb'");
adoRS.Open("Select * From tblName", adoConn, 1, 3);
adoRS.AddNew;
adoRS.Fields("FieldName").value = "Quentin";
adoRS.Update;
adoRS.Close();
adoConn.Close();
}
Removing a Record
function DeleteRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\dbName.mdb'");
adoRS.Open("Select * From tblName Where FieldName = 'Quentin'", adoConn, 1, 3);
adoRS.Delete;
adoRS.Delete;
adoRS.Close();
adoConn.Close();
}
Editing a Record
function EditRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\dbName.mdb'");
adoRS.Open("Select * From tblName Where FieldName = 'Quentin'", adoConn, 1, 3);
adoRS.Edit;
adoRS.Fields("FieldName").value = "New Name";
adoRS.Update;
adoRS.Close();
adoConn.Close();
}
Querying data:
var pad = "C:\\My Documents\\data.mdb";
var cn = new ActiveXObject("ADODB.Connection");
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pad;
cn.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "SELECT * FROM datatable";
rs.Open(SQL, cn);
if(!rs.bof) {
rs.MoveFirst();
if(!rs.eof) {
document.write("<p>" + rs.fields(1).value + ", ");
document.write(rs.fields(2).value + ", ");
document.write(rs.fields(3).value + ".</p>");
}
}
else {
document.write("No data found");
};
rs.Close();
cn.Close();
Home
»
database
»
javascript
»
programming
»
Tips
»
tricks
»
websites
» Access data in MS-Access database using Javascript
Thứ Sáu, 6 tháng 4, 2012
Đăng ký:
Đăng Nhận xét (Atom)
Bài đăng phổ biến
-
Want to check your Gmail inbox without pointing and clicking? You’ll barely have to touch your mouse with these handy keyboard shortcuts a...
-
Do you want to have free websites? With no costs? Even no Ads? There are many web hosting services that provide a free hosting , but they...
-
Apa yang anda rasakan ketika sebuah perusahaan berhasil memberikan pengalaman begitu besar, begitu pribadi, sehingga menciptakan respons emo...
-
Made the leap to the drastically revamped Windows 8 ? Feeling a little lost? You’re not the only one. Read on for eight tips that’ll help y...
-
Inbound links are the single most important factor in determining your position on Google’s results pages. Inbound links are good Here’s wha...
-
A recently updated and fresh list of top 10, top 50, and top 100+ best and free online ads posting classified ads websites around the int...
-
Malvertising is a word that has been bouncing around the internet for a while now. It refers to an increasingly common type of online hack,...
-
Despite the apparent advancement of HTML-driven websites and old-school methodology of designing Dreamweaver or NetObjects-based websites,...
-
Many millions of people worldwide enjoy connecting with friends and family via Facebook. We get a kick out of sharing baby pictures, funny...
-
Once your contacts are all loaded into your Google account, they’ll sync automatically with your Android handset, and presto! You’re all s...
0 nhận xét:
Đăng nhận xét