简体   繁体   English

我的代码有什么问题? 为什么我不能为从数据库中检索到的数据分配“ 0”

[英]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"">&nbsp;"
    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">&nbsp;<%=rs.fields.item("pd_id")%> </td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=rs.fields.item("pd_name")%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=PcsToDz(ActQty)%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%'=PcsToDz(rs.fields.item("SumOfpdtn_qty_est"))%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=dateshow%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=PcsToDz(sumQty)%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=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.

相关问题 代码中没有错误,但是从数据库中检索的数据未显示在列表框中 - No errors in code, but data retrieved from database doesn't show up in listbox 无法弄清楚我的 insert into 语句将 windows forms 文本框的数据插入 ms access 数据库中的一行有什么问题 - Can't figure out what's wrong with my insert into statement to insert data from a windows forms textbox to a row in ms access database 无法从 C# 保存到 MS Access 数据库 - Couldn't save to MS Access database from C# 找不到代码有什么问题 - Can't find what is wrong with the code 这段用于过滤数据的代码有什么问题? - What's wrong with this code for filtering data? 我的 VBA 代码有什么问题(我收到运行时错误 9) - What's wrong with my VBA code (I'm getting runtime error 9) 为什么我的 VBA 代码中出现数据不匹配错误 - Why Do i Get A Data Mismatch Error in my VBA Code 从数据库中指定关系可以得到什么? - What do I gain from specifying relationships in my database? 从Visual Studio C#中的MS Access数据库中获取OLE(位图)对象形式,我的代码有什么问题? - Taking OLE (bitmap) object form MS Access database in Visual studio C# , What's wrong in my code? 这个VBA代码有什么问题 - What is wrong with this VBA Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM