如果记录集中的值为 NULL,我该如何编写 VBS 来更改该值?
How do I write VBS to change a value in a recordset if it is NULL?
这是我的代码:
<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>
table 忽略了 "If IsNull(FS_Tax)" 语句。有什么想法吗?
我希望它将 table 中的值更改为 "None" 而不是只显示“%”表示 NULL 值。
变量FS_Tax没有声明。也许你的意思是数据库领域?如果是这样,请尝试以下操作:
If IsNull(Recordset("FS_Tax")) Then
正如@Fabio 提到的,FS_Tax
不是一个变量。如果它是 table 中的一列,您需要使用 Recordset("FS_Tax")
来检索它的值。
此外,您可以在原始 SQL 语句中考虑 NULL,而不必在 VBScript 中处理它:
select isnull(FS_Tax,'None')[FS_Tax] from ...
当您从记录集中读取它时,这将确保 FS_Tax
永远不会为空。
这是我的代码:
<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>
table 忽略了 "If IsNull(FS_Tax)" 语句。有什么想法吗?
我希望它将 table 中的值更改为 "None" 而不是只显示“%”表示 NULL 值。
变量FS_Tax没有声明。也许你的意思是数据库领域?如果是这样,请尝试以下操作:
If IsNull(Recordset("FS_Tax")) Then
正如@Fabio 提到的,FS_Tax
不是一个变量。如果它是 table 中的一列,您需要使用 Recordset("FS_Tax")
来检索它的值。
此外,您可以在原始 SQL 语句中考虑 NULL,而不必在 VBScript 中处理它:
select isnull(FS_Tax,'None')[FS_Tax] from ...
当您从记录集中读取它时,这将确保 FS_Tax
永远不会为空。