Use ASP to combine JavaScript or VBScript to generate a dynamic Web page. When this method is used in practical applications, it is unavoidable to print out the results. We can also sort out the results of the query and print the output directly using the print buttons on the browser toolbar. The following program is to access the sales table from the database pubs in SQL Server, with VBScript on both the server and the workstation side. Navigator access is available when the workstation side uses JavaScript.
〈html〉〈head〉
〈meta http-equiv=″content-type″content=″text/html; charset=gb-2312-80″〉
〈meta name=″vi60-defaultclientscript″content=″vbscript″〉
〈meta name=″generator″content=″microsoft FrontPage 3.0″〉
〈title〉sales〈/title〉〈/head〉
〈body〉〈form〉
〈table border=″0″width=″800″cellspacing=″0″cellpadding=″0″〉
The definition of the table width 800 points
〈tr〉〈td〉〈div align=″center″〉〈center〉〈h2〉〈strong〉 Order Report 〈/strong〉〈/h2〉
〈/center〉〈/div〉〈/td〉〈/tr〉〈tr〉〈td〉〈div align=″right″〉〈p〉 Unit: Yuan 〈/td〉〈/tr〉〈/table〉
〈table border=″1″width=″800″cellspacing=″0″cellpadding=″0″〉〈tr〉
〈TD width=″25%″align=″center″〉stor_id
〈/TD〉〈TD width=″25%″align=″center″〉ord_num〈/td〉
〈TD WIDTH=″25%″ALIGN=″CENTER″〉ORD_DATE〈/TD〉〈TD width=″25%″align=″center″〉qty〈/td〉〈/tr〉〈% Set cn= Server.CreateObject (″adodb.connection″)
The definition of an ADO Connection object
Cn.open″provider=sqloledb;data source=202.203.208.1;initial Catalog=pubs;user id=sa;password=; ″
To define a database connection
Sql=″select Stor_id,ord_num,ord_date,qty from sales where Ord_date〉′1994-5-1′″
Set Rs=cn.execute (SQL)
While not rs.eof
Is the last record of the decision?
Qtyv=rs (″qty″)
sumqtyv=sumqtyv+qtyv%〉
〈tr〉〈td〉〈%=rs (″stor_id″)%〉〈/td〉
〈td〉〈%=rs (″ord_num″)%〉〈/td〉
〈td〉〈%=rs (″ord_date″)%〉〈/td〉
〈td〉〈%=qtyv%〉〈/td〉〈/tr〉
〈%rs.movenext′ move to the next record wend%〉〈tr〉
〈TD colspan=″3″〉 Total 〈/td〉
〈td〉〈%=sumqtyv%〉〈/td〉
〈/tr〉〈/table〉〈%cn.close%〉〈/form〉〈/body〉〈/html〉
To ensure that you can print reports of various sizes, first set the paper size to the widest in the browser, and then output different report sizes by adjusting the value of the 〈table width=″″〉
Please replace "<" with ">" by yourself.