如果它是NULL,如何编写VBS来更改记录集中的值?

时间:2015-06-26 13:59:49

标签: html vbscript asp-classic

这是我的代码:

        <table width=600 Border=1 cellspacing=0 cellpadding=3>
            <tr>
                <td bgcolor = Blue><center><font Color = WHITE size ="2"><B>NUMBER</B></font></center></td>
                <td bgcolor = Blue><center><font Color = WHITE size ="2"><B>NAME</B></font></center></td>
                <td bgcolor = Blue><center><font Color = WHITE size ="2"><B>FS Tax</B></font></center></td>
                <td bgcolor = Blue><center><font Color = WHITE size ="2"><B>Beer Tax</B></font></center></td>
            </tr>   
            <%
            '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 "<tr>"
            Response.write "<td>" & Recordset("Number") & "</td>"
            Response.write "<td>" & Recordset("Location_Name") & "</td>"
            If IsNull(FS_Tax) Then
                Response.write "<td>" & "None" & "</td>"
            End If
            Response.write "<td>" & Recordset("FS_Tax") & "%" & "</td>"
            Response.write "<td>" & Recordset("Beer_Tax") & "%" & "</td>" 
            Response.write "</tr>" 
            Recordset.MoveNext     
            Loop
            End If
            %>
        </table>

该表忽略了“If IsNull(FS_Tax)”语句。有什么想法吗?

我希望它将表中的值更改为“None”,而不是仅显示NULL值的“%”。

2 个答案:

答案 0 :(得分:2)

正如@Fabio所提到的,FS_Tax不是变量。如果它是表格中的列,则需要使用Recordset("FS_Tax")来检索其值。

此外,您可以在原始SQL语句中考虑NULL,而不必在VBScript中处理它:

select isnull(FS_Tax,'None')[FS_Tax] from ...

当您从记录集中读取它时,这将确保FS_Tax永远不会为空。

答案 1 :(得分:1)

未声明变量 FS_Tax 。也许你的意思是数据库领域?如果是这样,请尝试以下操作:

If IsNull(Recordset("FS_Tax")) Then