【问题标题】:Classic ASP why nothing being display on screen?经典的 ASP 为什么屏幕上什么都没有显示?
【发布时间】:2015-05-23 08:38:24
【问题描述】:

SQL 将返回 2 个值,但是当我在经典 ASP 页面上运行时

我的输出返回为 电子邮件发送日期 电子邮件 电子邮件发送日期 电子邮件 哪里不对了?这里的正确语法是什么?

<% 
'declare the variables 
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL

'define the connection string, specify database driver
ConnString="Driver={SQL Server};Server=10.0.0.96;Database=VISTAIT;Uid=sa;Pwd=CqLxxxx1;"

'declare the SQL statement that will query the database
SQL = "SELECT OrderH_dtmInitiated,OrderH_strEmailConfirmationSent  ,OrderH_strEmail FROM tblOrderHistory WHERE  OrderH_strEmailConfirmationSent is NULL And OrderH_dtmInitiated >= (SELECT  DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-1))) ORDER by OrderH_dtmInitiated" 

'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

'Open the connection to the database
Connection.Open ConnString

'Open the recordset object executing the SQL statement and return records 
Recordset.Open SQL,Connection

'first of all determine whether there are any records 
If Recordset.EOF Then 
Response.Write("No records returned.") 
Else 
'if there are records then loop through the fields 
Do While NOT Recordset.Eof   

Response.write "<br>"   
Response.Write("Date " &OrderH_dtmInitiated )
Response.Write("Email Sent " &OrderH_strEmailConfirmationSent)
Response.write "<br>"   
Response.Write("Email " &OrderH_strEmail)
Response.write "<br>"    
Recordset.MoveNext     
Loop
End If

'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>

【问题讨论】:

    标签: sql asp-classic


    【解决方案1】:

    假设记录集有 2 条记录。

    那么循环内的response.writes不应该写入未声明的ASP变量,而是记录集对象的元素。正确的编码应该是

    Response.Write("Date " & Recordset("OrderH_dtmInitiated") )
    Response.Write("Email Sent " & Recordset("OrderH_strEmailConfirmationSent"))
    Response.write "<br>"   
    Response.Write("Email " & Recordset("OrderH_strEmail"))
    

    【讨论】:

    • 如果 OrderH_strEmailConfirmationSent 值为 null 我注意到它不会显示任何值...我们应该如何在 asp 对象上显示 NULL ?
    • 使用TRIM(rs(|"value") &amp; " ") 编辑视图以使其永远不会有NULL 值,或者创建一个小循环以接受数组中的记录集值。空格将泛型类型强制转换为字符串,修剪再次删除空格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    相关资源
    最近更新 更多