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...
-
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...
-
Once your contacts are all loaded into your Google account, they’ll sync automatically with your Android handset, and presto! You’re all s...
-
You’ve heard of that clothing line called “Life is Good,” right? That Jake character has it goin’ on! His glass is half-full, and the dude j...
-
Developing and releasing a mobile app can be an expensive and time-consuming project. But the work does not end once the programmers figure ...
-
Sometimes SEOs and site owners encounter the problem of their sites suddenly going down in the search engine results pages for no particular...
-
Dengan 2 versi utama dan total 5 update sejak 2012, maka akan lebih bijaksana untuk mengatakan bahwa Google Penguin telah mengguncang seluru...
-
Before attempting to clean any infections from your computer it's important to make sure that the computer is actually infected. If you...
-
Apa yang anda rasakan ketika sebuah perusahaan berhasil memberikan pengalaman begitu besar, begitu pribadi, sehingga menciptakan respons emo...
-
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,...
0 nhận xét:
Đăng nhận xét