DataView RowFilter problem

  • Thread starter Thread starter Peter Hemmingsen
  • Start date Start date
P

Peter Hemmingsen

Hi,

I've found a very strange behavior when using IsNull in a RowFilter. The
following line:

dv.RowFilter="Isnull(int64, -9223372036854775808) = -9223372036854775808";
// Min64

works just fine. But the following:

dv.RowFilter="Isnull(int64, -9223372036854775807) = -9223372036854775807";
// Min64+1

fails with an error saying that it can't compare an Int64 with an
Int64??????

What is going on?

Peter
 
Hi Peter:

I've tested it using the number you mention and I'm not having the
problem..works fine. However, if I use positive numbers it won't b/c the
range is -9,223,372,036,854,775,808 through positive
9,223,372,036,854,775,807, so if I use a ++ then I'll overrun the type,
but -807 is less than -808 so that's not a problem. I'm just wondering if
you're using literals or if you are using MinValue/MaxValue. I'd normally
use those just to be safe (it'd be easy to type one number wrong altough the
ones you have below are correct) but to replicate the problem I used the
hard coded values. First off,the assertions all pass but that's not really
the issue, that's just how I am illustrating that there's no typo in my
numbers.. since Min Value equals the hard coded number we know that's good.
Since MinValue + 1 (since it's negative) = the second number, we know
there's no typo there either. Anyway, not sure what it could be but I've
used the exact code and can't replicate it. Stupid question but that is the
exact code that's throwing the exception right? Try doing it with MinValue
and MinValue +1 and see if it persists. One more thing. I suspected that
the problem may be with a project setting for Checked vs. UnChecked code.
Perhaps if it was checked it would throw an exception if you had overflow
but if you had a typo and it was unchecked, it might let it slip through
(But we've verified that there's not a typo). But I ran the same code
changing the check for overflow and wrapped it in checked and unchecked in
the code and still didn't get an exception. That's really puzzling too b/c
if IsNull converts it to the Int64 default, and the number you used was
bigger than an Int64, i'd really expect it to bomb, wouldn't you? I mean
each time it sees null, it's inserting the value that you specify and that
value has to be an Int64. Now, here's the really interesting part, if I
switch the numbers for the first one for instance and use
IsNull(myInt64Column, 'Bill') = 'Bill', where it's expecting a Int64 instead
of a string, I get a DataEvaluation Error saying it can't compare Int64 to
String. That makes sense, but if why wouldn't it let you compare two Int64
values if they are both legit and it's even more weird that it works on one
machine and not another even though it's the same code. You are right, it's
weird indeed.


Int64 i = Int64.MinValue;
Debug.WriteLine(i.ToString());

Debug.WriteLine((i+1).ToString());

Debug.Assert(i == -9223372036854775808, "Min Value Ok");

dv.RowFilter = "IsNull(myInt64Column, -9223372036854775808)
= -9223372036854775808";

MessageBox.Show("-9223372036854775808", "First One Worked");

i++;

Debug.Assert(i == -9223372036854775807, "-1 Worked");

dv.RowFilter = "IsNull(myInt64Column, -9223372036854775807)
= -9223372036854775807";

MessageBox.Show("-9223372036854775807", "Second One Worked");
 
Hi Peter,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that if you use a number which is 1 larger
than Int64.MinValue, the RowFilter crashes with an EvaluationException. If
there is any misunderstanding, please feel free to let me know.

I have tried it on my machine and was able to reproduce it. I have been
reported this issue to our development team. For workaround, please use
Int64.MaxValue as the null value. I will let you know if I get any update
from them.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi William,

Thanks a lot for your answer. It appears that the bug only shows when the
dataview is not empty. Below is some sample code that will reproduce the
problem:

DataTable dt=new DataTable();
dt.Columns.Add("int64", Type.GetType("System.Int64"));
int i;
DataRow dr;
for (i=0; i<10; i++) {
dr=dt.NewRow();
dr[0]=i;
dt.Rows.Add(dr);
}
dt.Rows.Add(dt.NewRow());
dr=dt.NewRow();
dr[0]=-9223372036854775807;
dt.Rows.Add(dr);
DataView dv=new DataView(dt);
dv.RowFilter="Isnull(int64, -9223372036854775807) = -9223372036854775807";
for (i=0; i<dv.Count; i++) {
dr=dv.Row;
if (dr.IsNull(0))
System.Console.WriteLine ("Null");
else
System.Console.WriteLine ("{0}", dr[0]);
}
System.Console.WriteLine ("Press <Enter>");
System.Console.ReadLine();


Peter
 
You're welcome, peter.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top