2012-11-15 40 views
1

我在使用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腳本從我的數據庫獲取數據,運行上面我只是有一個空白頁面的代碼之後。任何人都可以請幫忙嗎?

+1

對於初學者來說,你錯過了'FROM'在'SELECT'聲明:'STRSQL = 「SELECT * FROM npic.dbo.LMSWeb」' – LittleBobbyTables

+0

SRY忘記鍵入部分 –

+0

哥們,FONT標籤10年前走出了窗戶。使用CSS。 –

回答

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"> 
<% 
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稍微更現代的語法的自由爲<font>標籤出去的style(雙關語意)當HTML 4出現時,你明確想要的是表頭部分。

+0

嗨皮特,我跑上面的代碼更新「從」選擇表和我的連接字符串,但仍然結束了一個空白頁。 –

+0

您是否檢查過以確保您的查詢實際返回數據? – pete

+0

如果我在sql服務器中運行查詢,我返回的數據,但不是在asp頁面 –

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>