-1

The MS Access (2013) database has the following table ImportFromExcel (16 columns). I just want to see the table in a browser. Any help is appreciated :)

<html>
    <head>
    <title>Import From Excel</title>

    <script type="text/javascript">

    function query()
    {
        var pad = "C:\\Users\\azi!z\\Desktop\\Project\\Test.accdb";
        var cn = new ActiveXObject("ADODB.Connection");
        var strConn = "Provider=microsoft.ace.oledb.12.0;Data Source=" + pad;
        cn.Open(strConn);
        var rs = new ActiveXObject("ADODB.Recordset");
        var SQL = "SELECT * FROM ImportFromExcel";
        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();
    }

    </script>
    </head>
    </html>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Aziiz Pc
  • 49
  • 3
  • 11

1 Answers1

0

It appears you have a typo in your code

desktop in your file path

var pad = "C:\\Users\\azi!z\\esktop\\Project\\Test.accdb";

If this is not the problem then please update your question and describe the problem instead of only the goal.

It appears you were not calling the function you declared in the head

Use this code below which is not in a function or call the function you declared.

Please this code,

  <html>
    <head>
    <title>Access db Connection</title>


    <script type="text/javascript">

    var pad = "C:\\Users\\azi!z\\Desktop\\Project\\Test.accdb";

    //var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pad;
    var strConn = "Provider=microsoft.ace.oledb.12.0;Data Source=" + pad;

    var cn = new ActiveXObject("ADODB.Connection");

    cn.Open(strConn);
    var rs = new ActiveXObject("ADODB.Recordset");
   // var SQL = "SELECT * FROM customer_mas WHERE ID='512225'";
      var SQL = "SELECT * FROM ImportFromExcel";    
rs.Open(SQL, cn);
    if(!rs.bof) {
    rs.MoveFirst();
    if(!rs.eof) {
    document.write("<p><br>" + rs.fields(1).value + ", ");
    document.write("<br>" + rs.fields(2).value + ", ");
    document.write("<br>" + rs.fields(3).value + ".</p>");
    }
    }
    else {
    document.write("No data found");
    };
    rs.Close();
    cn.Close();

    </script>

    </head>

    </html>
wuno
  • 9,547
  • 19
  • 96
  • 180
  • Thanks for pointing out. But, that's not the problem it seems. When I open the .html file, it's showing a blank page whereas, I'm expecting the table row to be displayed. *File path updated – Aziiz Pc Dec 27 '15 at 08:32
  • Checked. No errors. Also, I have tried in both the browsers. IE 10 and mozilla. – Aziiz Pc Dec 27 '15 at 08:39
  • Ya it is. I have uploaded the MS Access screenshot here https://unsee.cc/noguzepa/ – Aziiz Pc Dec 27 '15 at 09:23