简体   繁体   English

如何将 html 与 sql server 连接

[英]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我有一些数据库查询,他们的数据需要以表格和图形的形式显示在 html 上

<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.您可以在数据库端生成 html 报告,并在 Web 应用程序中简单地显示生成的 html。

You can use FOR XML Clause to generate HTML report.您可以使用FOR XML 子句生成 HTML 报告。

There are many samples provided in the Generating HTML reports using SQL Queries article 使用 SQL 查询生成 HTML 报告一文中提供了许多示例

Also refer to below stackoverflow answers.另请参阅以下 stackoverflow 答案。

- how do I convert a select statement result into an HTML table in SQL Server? - 如何在 SQL Server 中将选择语句结果转换为 HTML 表?
- Convert a SQL query result table to an HTML table for email - 将 SQL 查询结果表转换为用于电子邮件的 HTML 表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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