【问题标题】:divide by 0 problem vb.net除以 0 问题 vb.net
【发布时间】:2011-05-23 17:43:05
【问题描述】:

如何确保 PCTofSales 不为 0。

  'gets the projected sales by dividing the currentsales by the percent of sales
    Dim projectedye As New DataColumn
    projectedye = New DataColumn("ProjSales", GetType(Double))
    projectedye.Expression = "CurrentSales / (PCTofSales)"

【问题讨论】:

    标签: asp.net vb.net ado.net dataset


    【解决方案1】:

    假设您使用的是 .NET 3.5:

    pctofsales.Expression = "IIF([YEsales] = 0, 0, [ASOFSales] / [YEsales])"
    

    请参阅此处:MSDN's article,了解有关可在表达式中使用的函数的信息。

    【讨论】:

    • 应该是 IF 不是 IIF 吗? IF 仅评估其参数之一。 IIF 评估两者。
    【解决方案2】:

    在以下情况下你能不能不使用 IF THEN 来调用函数:

    “[ASOFSales] / [YEsales]”

    等于零还是不宜除?

    【讨论】:

    • 我试过了,但我似乎无法得到它,因为数据在数据列中,所以我很难
    • 在那里你可以使用 if then。如果必须,您可以测试各个值并做出决定。你的头不会那么那么痛吧? :)
    • 是的,问题是 if then 语句不起作用,我会发布它们
    【解决方案3】:

    对您的数据集运行更新以将所有 0 更改为 NULL 或更改您的数据源以在 PCTofSales/其他列中返回 NULL 而不是 0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-09
      相关资源
      最近更新 更多