1

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 スクリプトを使用してデータベースからデータを取得する際に問題が発生しました。上記のコードを実行した後、空白のページが表示されます。誰でもこれを手伝ってもらえますか?

4

2 に答える 2

1

Classic 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>

<font>HTML 4 がシーンにヒットし、明らかに必要だったのはテーブル ヘッダー セクションで、タグがなくなったためstyle(しゃれが意図されていた)、HTML を少し最新の構文に更新する自由を取りました。

于 2012-11-15T21:26:41.320 に答える
0

初期化する前に rst 変数と strSQL 変数を宣言していないことに気付きました (例: Dim rst,strSQL)。以下に追加しました。

<% 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 rst, strSQL
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>
于 2015-03-16T18:03:47.593 に答える