[英]What wrong with my code? Why couldn't I assign “0” to data that being retrieved from database
Since in database there are some records that have Null value of them, this code was being created to filter the recordset that have no value assigned in "rsActQty" or "rsSumQty". 由于在数据库中有一些记录具有Null值,因此将创建此代码来过滤没有在“ rsActQty”或“ rsSumQty”中分配值的记录集。 However no matter what I tried, it seemed that this code cannot detect Null value.
但是,无论我尝试了什么,似乎这段代码都无法检测到Null值。 And I don't know what did I done wrong.
而且我不知道我做错了什么。 So could you please give me some suggestion?
那你能给我一些建议吗? Thank you.
谢谢。 (This db was in MSACCESS)
(此数据库位于MSACCESS中)
What I want is : - To display only records that have value in either "rsActQty" OR "rsSumQty". 我想要的是:-仅显示具有“ rsActQty”或“ rsSumQty”值的记录。 - When one of this fields was NULL assign "0" to it.
-当此字段之一为NULL时,为其分配“ 0”。
<%
if Rs.eof then
response.write "<tr><td colspan=""6""> "
call displayNotFoundRecord
response.write "</td></tr>"
Else
Dim ActQty, sumQty, Total, rsActQty, rsSumQty, rsPdtn_qty_est, inv_date, res_date
Do while Rs.AbsolutePage = strPageCurrent And Not Rs.EOF
inv_id = rs.fields.item("inv_idRS")
rsActQty = rs.fields.item("sumOfinv_qty_act")
rsSumQty = rs.fields.item("SumOfres_qty")
rsPdtn_qty_est = rs.fields.item("SumOfpdtn_qty_est")
inv_date = rs.fields.item("inv_dateRS")
res_date = rs.fields.item("res_dateRS")
if rsActQty = "" then
ActQty = 0
else
ActQty = rsActQty
end if
if rsSumQty = "" then
sumQty = 0
else
sumQty = rsSumQty
end if
if rsActQty <> "" OR rsSumQty <> "" then
if inv_date = "" then
dateshow = res_date
else
dateshow = inv_date
end if
if res_date = "" then
dateshow = res_date
else
dateshow = res_date
end if
total = rs.fields.item("Total")
%>
<tr class='difcursor'>
<td class="btline" width="25" align="center"><input type="checkbox" name="inv_id" value="<%=inv_id%>" onClick="highlightRow(this,'#FFFFCC','#EFF4FA');"></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%=rs.fields.item("pd_id")%> </td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%=rs.fields.item("pd_name")%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%=PcsToDz(ActQty)%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%'=PcsToDz(rs.fields.item("SumOfpdtn_qty_est"))%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%=dateshow%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%=PcsToDz(sumQty)%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px"> <%=PcsTODz(Total)%></td>
<td class="btline"></td>
</tr>
<%
end if
Rs.movenext
Loop
End if
Rs.close
set Rs=nothing
Call DBConnClose()
%>
Try using the isNull function. 尝试使用isNull函数。 For instance
例如
if not isNull(rs.fields.item("sumOfinv_qty_act")) then
ActQty = rs.fields.item("sumOfinv_qty_act")
else
ActQty = 0
end if
Null is not same as blank value. 空值与空白值不同。
You could try forcing the null to a string and do the comparing: 您可以尝试将null强制为字符串并进行比较:
rsActQty = "" & rs.fields.item("sumOfinv_qty_act")
rsSumQty = "" & rs.fields.item("SumOfres_qty")
you could also handle null in your sql query like: 您还可以在SQL查询中处理null,例如:
select iif(isnull(fieldname),0,fieldname) as fieldname from table
which will return a 0 for the null value. 这将为空值返回0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.