Re: DataColumn.Expression error handling

From: Miha Markic [MVP C#] (miha)
Date: 07/01/04


Date: Thu, 1 Jul 2004 13:45:44 +0200

Hi pali,

This is vb behaviour where IIF is a procedure that you pass parameters to.
It is not the same as ?: operator in C# I believe.
Thus you might modify it a bit just to avoid an exception:
IIF(budget_ext_price = 0, 'NaN', material_margin / iif(budget_ext_price=0,
1, budget_ext_price))"

Didn't test it but it might work :-)

-- 
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
"pali" <pali@discussions.microsoft.com> wrote in message
news:607B25D3-2DC9-42F5-AF61-C3AA54EED884@microsoft.com...
> Hi,
> I need to compute a percentage in a DataTable, so i'm trying to use the
Expression property provided by the DataColumn object. My problem is the
classic division by zero error.
> This is my expression:
> "IIF(budget_ext_price = 0, 'NaN', material_margin / budget_ext_price)"
> Now, it seems that the material_margin / budget_ext_price expression is
being evaluated regardless of the condition. If i replace the '/' with '-',
I get correctly NaN in one row, though with '/' I get division by zero
exception. Is the false part really being evaluated, even in the case the
condition is true?


Relevant Pages

  • Re: DataColumn.Expression error handling
    ... > This is vb behaviour where IIF is a procedure that you pass parameters to. ... > Thus you might modify it a bit just to avoid an exception: ... > classic division by zero error. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataColumn.Expression error handling
    ... would never be 0 but 1 instead, and I would really like to display the NaN ... >> classic division by zero error. ... >> being evaluated regardless of the condition. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataColumn.Expression error handling
    ... Expression property provided by the DataColumn object. ... classic division by zero error. ... being evaluated regardless of the condition. ... I get correctly NaN in one row, though with '/' I get division by zero ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: division by zero mystery
    ... in VB seems to work correctly in the C routines. ... This generates a division by zero error in VB when the complex ... throw a floating point exception, ... atan() cannot guess the right quadrant like ...
    (comp.programming)
  • JDBC and handling of errors
    ... generates a divide by zero error in QA, but does not produce an exception in the Java program. ...
    (microsoft.public.sqlserver.clients)