简体   繁体   中英

How to connect html with sql server

I have some database queries whom's data needs to be displayed over the html in the form of tables and graphs

<script>
    var objConnection = new ActiveXObject("adodb.connection");
    var strConn = "driver={sql server};server=ip;database=databasename;uid=username;password=password”;
    objConnection.Open(strConn);
    var rs = new ActiveXObject("ADODB.Recordset");
    var strQuery = "SELECT TOP 10 * FROM dbo.nodes";
    rs.Open(strQuery, objConnection);
    rs.MoveFirst();
    while (!rs.EOF) {
                document.write(rs.fields(0) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(1) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(2) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(3) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(4) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(5) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(6) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(7) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(8) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(9) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(10) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                document.write(rs.fields(11) + "<br/>");
     rs.movenext();
    }
</script>

You can generate html report in the database side and simply display the generated html in the web application.

You can use FOR XML Clause to generate HTML report.

There are many samples provided in the Generating HTML reports using SQL Queries article

Also refer to below stackoverflow answers.

- how do I convert a select statement result into an HTML table in SQL Server?
- Convert a SQL query result table to an HTML table for email

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM