经典ASP从数据库中提取数据 [英] Classic Asp to pull data from database

查看:75
本文介绍了经典ASP从数据库中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行下面的代码后,我在使用asp脚本从数据库中获取数据时遇到问题,我的页面只有空白.有人可以帮忙吗?

<% Response.Buffer = True %>
<% Response.Expires = 0%>
<!--#include file="dsn.inc"-->

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Search Results</title>
</head>

<body>
<font face="Arial Narrow">
<%
Set rst = Server.CreateObject("ADODB.Recordset")

If LCase(Request("clearsql")) = "y" Then




        strSQL = "SELECT * from npic.dbo.LMSWeb"


    Session("sql") = strSQL



Else

    strSQL = Session("sql")

End If

rst.Open strSQL, strDSN

%>


<table border="1" width="100%">
<tr>
<td align="center" width="212"><font face="Arial Narrow"><b>Agent Name </b>
</font></td>
<td align="center" width="140"><b><font face="Arial Narrow">Sup</font></b><font
face="Arial Narrow"><b> Name </b>
</font></td>
<td align="center"><font face="Arial Narrow"><b>Date</b></font></td>
<td align="center"><font face="Arial Narrow"><b>Points</b></font></td>
<td align="center">&nbsp;</td>
</tr>
<%

Dim strError

Do While Not rst.EOF

Response.Write "<tr>" & Chr(10)
Response.Write "    <td>" & rst("agent name") & "</td>" & Chr(10)
Response.Write "    <td>" & rst("sup") & "</td>" & Chr(10)
Response.Write "    <td>" & rst("date") & "</td>" & Chr(10)
Response.Write "    <td>" & rst("points") & "</td>" & Chr(10)


Response.Write "</tr>" & Chr(10)
rst.MoveNext
loop

rst.Close
Set rst=Nothing

%>
</table>
</center></div>


</body>
</html>

运行上面的代码后,我使用asp脚本从数据库中获取数据时遇到问题,我只有一个空白页.有人可以帮忙吗?

解决方案

自经典ASP以来已经有一段时间了,但是我认为这会起作用:

<% Response.Buffer = True %>
<% Response.Expires = 0 %>
<!--#include file="dsn.inc"-->
<html>
<head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Search Results</title>
</head>
<body>
    <font face="Arial Narrow">
<%
Dim conn

Set rst = Server.CreateObject("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open yourConnectionStringHere

If LCase(Request("clearsql")) = "y" Then
    strSQL = "SELECT * npic.dbo.LMSWeb"
    Session("sql") = strSQL
Else
    strSQL = Session("sql")
End If

Set rst = conn.Execute(strSQL) 'Typo was on this line
%>
    <table border="1" width="100%" style="font-family: Arial Narrow;">
        <thead>
            <tr>
                <th width="212">Agent Name</th>
                <th width="140">Sup Name</th>
                <th>Date</th>
                <th>Points</th>
                <th>&nbsp;</th>
            </tr>
        <thead>
        <tbody>
<%
Dim strError

If rst.BOF And rst.EOF Then
    ' No data
Else
    Do While (Not rst.EOF)
        Response.Write "<tr>" & Chr(10)
        Response.Write "    <td>" & rst(0) & " " & rst(1) & "</td>" & vbCrLf
        Response.Write "    <td>" & rst(2) & "</td>" & vbCrLf
        Response.Write "    <td>" & rst(3) & "</td>" & vbCrLf
        Response.Write "    <td>" & rst(4) & "</td>" & vbCrLf
        Response.Write "</tr>" & vbCrLf
        rst.MoveNext
    Loop
End If

rst.Close
conn.close

Set conn = Nothing
Set rst = Nothing
%>
        </tbody>
    </table>
</body>
</html>

当HTML 4出现时,我很自由地将HTML更新为更现代的语法,因为<font>标记从style(双关语意味)中消失了,而您显然想要的是表格标题部分.

I'm having a problem getting data from my database using asp script, after running the codes below I'm just having a blank page. could anyone please help with this?

<% Response.Buffer = True %>
<% Response.Expires = 0%>
<!--#include file="dsn.inc"-->

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Search Results</title>
</head>

<body>
<font face="Arial Narrow">
<%
Set rst = Server.CreateObject("ADODB.Recordset")

If LCase(Request("clearsql")) = "y" Then




        strSQL = "SELECT * from npic.dbo.LMSWeb"


    Session("sql") = strSQL



Else

    strSQL = Session("sql")

End If

rst.Open strSQL, strDSN

%>


<table border="1" width="100%">
<tr>
<td align="center" width="212"><font face="Arial Narrow"><b>Agent Name </b>
</font></td>
<td align="center" width="140"><b><font face="Arial Narrow">Sup</font></b><font
face="Arial Narrow"><b> Name </b>
</font></td>
<td align="center"><font face="Arial Narrow"><b>Date</b></font></td>
<td align="center"><font face="Arial Narrow"><b>Points</b></font></td>
<td align="center">&nbsp;</td>
</tr>
<%

Dim strError

Do While Not rst.EOF

Response.Write "<tr>" & Chr(10)
Response.Write "    <td>" & rst("agent name") & "</td>" & Chr(10)
Response.Write "    <td>" & rst("sup") & "</td>" & Chr(10)
Response.Write "    <td>" & rst("date") & "</td>" & Chr(10)
Response.Write "    <td>" & rst("points") & "</td>" & Chr(10)


Response.Write "</tr>" & Chr(10)
rst.MoveNext
loop

rst.Close
Set rst=Nothing

%>
</table>
</center></div>


</body>
</html>

I'm having a problem getting data from my database using asp script, after running the codes above I'm just having a blank page. could anyone please help with this?

解决方案

It's been a while since Classic ASP, but I think this will work:

<% Response.Buffer = True %>
<% Response.Expires = 0 %>
<!--#include file="dsn.inc"-->
<html>
<head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Search Results</title>
</head>
<body>
    <font face="Arial Narrow">
<%
Dim conn

Set rst = Server.CreateObject("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open yourConnectionStringHere

If LCase(Request("clearsql")) = "y" Then
    strSQL = "SELECT * npic.dbo.LMSWeb"
    Session("sql") = strSQL
Else
    strSQL = Session("sql")
End If

Set rst = conn.Execute(strSQL) 'Typo was on this line
%>
    <table border="1" width="100%" style="font-family: Arial Narrow;">
        <thead>
            <tr>
                <th width="212">Agent Name</th>
                <th width="140">Sup Name</th>
                <th>Date</th>
                <th>Points</th>
                <th>&nbsp;</th>
            </tr>
        <thead>
        <tbody>
<%
Dim strError

If rst.BOF And rst.EOF Then
    ' No data
Else
    Do While (Not rst.EOF)
        Response.Write "<tr>" & Chr(10)
        Response.Write "    <td>" & rst(0) & " " & rst(1) & "</td>" & vbCrLf
        Response.Write "    <td>" & rst(2) & "</td>" & vbCrLf
        Response.Write "    <td>" & rst(3) & "</td>" & vbCrLf
        Response.Write "    <td>" & rst(4) & "</td>" & vbCrLf
        Response.Write "</tr>" & vbCrLf
        rst.MoveNext
    Loop
End If

rst.Close
conn.close

Set conn = Nothing
Set rst = Nothing
%>
        </tbody>
    </table>
</body>
</html>

I took the liberty of updating your HTML to slightly more modern syntax as <font> tags went out of style (pun intended) when HTML 4 hit the scene and what you clearly wanted was a table header section.

这篇关于经典ASP从数据库中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆