0

i am doing a query thus:

int numberInInterval = (from dsStatistics.J2RespondentRow item in jStats.J2Respondent
                   where item.EndTime > dtIntervalLower && item.EndTime <= dtIntervalUpper
                   select item).count();

there appear to be some dbnulls in the endtime column.. any way i can avoid these?

tried adding && where item.endtime != null.. and even != dbnull.value

do i have to do a second (first) query to grab all that arent null then run the above one?

im sure its super simple fix, but im still missing it.. as per

thanks nat

4

3 回答 3

1

I think you want to use item.EndTime.HasValue, and not item.EndTime == null.

于 2009-12-03T18:34:47.107 回答
1

最简单的方法是在可以为空的值上使用 .GetValueOrDefault(...一些合理的默认值...) ,这样可以避免错误。

于 2009-12-03T21:52:37.263 回答
0

The way I typically do this in a T-SQL query is to use ISNULL on the date, and set the date to something like '12/31/2099' when it's null.

With Linq it could be something like this:

from t in MyTable where Convert.ToString((Convert.ToString(t.MyDateColumn) ?? "12/31/2099")) < MyTargetValue

于 2009-12-03T18:31:53.960 回答