Reading and formatting Access data

烂漫一生 提交于 2019-12-11 11:24:11

问题


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();
}

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.

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.

If I was getting the text from a .txt file I'd use

while(!lyrics.AtEndOfStream) {
    box.innerHTML += '<a id="miseryBusiness">' + lyrics.ReadLine() + '<br/>';
}

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


回答1:


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/>');


来源:https://stackoverflow.com/questions/16423359/reading-and-formatting-access-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!