2012-11-15 42 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>