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...
-
After I earned a lots of point & registered some offer , they Nullified my Point & Earned Cash , they send me an email with the fol...
-
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...
-
This tools is my School Project , it useful when you have to download all attachment from a lot of mail in Gmail account. Tools describe : ...
-
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...
-
With the blogosphere churning out nearly 1 million posts every 24 hours, an unstoppable river of content flows over the web daily. It’s d...
-
Do you want to play webgame & win Real Cash? Join Dungeons & Treasure, it's an Adventure Webgame that pays you. Click here to...
-
Typing Captcha and earn money Rate: 0.85 -> 1.35 per 1000 pic You go to http://megatypers.com to register INVITATION CODE: KIH DOW...
-
Having a proper marketing budget can make or break your business - it's one of those facets of owning a company that is absolutely cruci...
0 nhận xét:
Đăng nhận xét