Goodspeed

导航

自适应输出表格(ASP版)

<%
'
'
    Made by Goodspeed
'
'
    
Option Explicit 
Response.Buffer 
= True
'sql数据库连接参数:数据库名、用户密码、用户名、连接名(本地用local,外地用IP)
Const SqlUsername = "sa"
Const SqlPassword = "qwe"
Const SqlDatabaseName = "NorthWind"
Const SqlLocalName = "127.0.0.1"
Dim ConnStr

ConnStr 
= "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"

'打开数据库
Dim Conn
Set Conn=server.createobject("adodb.connection")
Conn.Open ConnStr
%
>
<html>
<head>
    
<title>ASP Test</title>
    
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<table>
<%
Dim rs, strSQL, Field, strResponse

strSQL 
= "SELECT EmployeeID,LastName,FirstName FROM Employees;"
Set rs = Conn.Execute(strSQL)


'输出表头
strResponse = "<tr>"
For Each Field In rs.Fields
    strResponse 
= strResponse & "<td>" & Field.Name & "</td>"
Next
strResponse 
= strResponse & "</tr>"

'输出表体
Do Until rs.EOF
    strResponse 
= strResponse & "<tr>"

    For Each Field In rs.Fields
        strResponse 
= strResponse & "<td>" & rs(Field.Name)  & "</td>"
    Next
    
    strResponse 
= strResponse & "</tr>"
    rs.MoveNext
Loop
Set rs = nothing
Response.Write (strResponse)
%
>
</table>
</body>
</html>
<%
Conn.Close()
Set Conn = nothing
%
>

posted on 2004-08-12 13:52  Goodspeed  阅读(1619)  评论(2编辑  收藏  举报