读取和格式化访问数据 [英] Reading and formatting Access data
问题描述
我使用JavaScript和HTA在本地访问数据库(.mdb)中读取数据,但有一个小问题。我的JavaScript代码是这样的:
I'm using JavaScript and HTA to read data in access database (.mdb) on local but having a small issue. My JavaScript code is like this:
function miseryBusiness() {
var box = document.getElementById("lyrics");
box.innerHTML = "";
var db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='paramore.mdb'";
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open(db);
adoRS.Open("SELECT * from 2007_RIOT WHERE track=4", adoConn, 1, 3);
var lyrics = adoRS.Fields("lyrics").value;
box.innerText = lyrics;
adoRS.Close();
adoConn.Close();
}
我在页面中有一个div,id =lyrics。函数获取指定单元格的值,并将其div的内部文本更改为该值。
I have a div in the page with id="lyrics". Function gets the specified cell's value and change's div's inner text to that value.
我想要做的是使用innerHTML而不是innerText。如果我使用内部HTML,我得到单元格的值作为一行。我想在每行的末尾添加换行符。
What I want to do is use innerHTML instead of innerText. And if I use inner HTML I get the cell's value as a single line. I want to add line breaks to the end of the each line. Also an anchor to the beginning of the text.
如果我从.txt文件中获取文本,我会使用
If I was getting the text from a .txt file I'd use
while(!lyrics.AtEndOfStream) {
box.innerHTML += '<a id="miseryBusiness">' + lyrics.ReadLine() + '<br/>';
}
但这不适用于access数据库。或者我不能让它工作。任何想法?
but this doesn't work with access database. Or I couldn't get it to work. Any ideas?
The HTA and .mdb file I'm using: link1 link2
推荐答案
如果歌词在具有硬换行符的备注字段中,则行终止符几乎肯定为< cr>< lf& code>,因此请尝试以下操作:
If the lyrics are in a Memo field with hard line-breaks then the line terminator is almost certainly <cr><lf>
, so try the following:
box.innerHTML = '<a id="miseryBusiness">' + lyrics.replace(/\r\n/g, '<br/>');
这篇关于读取和格式化访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!