Post by William Ryan eMVPThat's pretty interesting. I'm guessing the same applies for datatable
values? I actually have a good bit of code using IsDbNull that I probably
need to change.
No it's just with datareader's IsDBNull. DataTable's IsNull is in fact the
DataRow's IsNull, which is just an in-memory check of a column value at a
given index. I found the slowness of IsDBNull after profiling my O/R mapper's
performance and notices a severe dip in performance in the datareader loop,
and hte profiler showed 15-20% of the time the loop was spending in
IsDBNull!. So I changed it to a compare with DBNull.Value and the routine
gained a significant amount of performance :)
Post by William Ryan eMVPAs an aside, if you are in a read only scenario from the db (ie you won't
send back an Update) - is using IsNull() [assuming you are using SQL Server
or a db that supports it] on the server a decent alternative?
Definitely, IF you don't have any logic working on NULL values. I mean: if
you read a set of rows and the logic working with the values has to display
something like "Not available" when a field is NULL (not defined), you should
read the NULL values as well.
I use default values for NULL values on the client. This means that the
field's NULL value is noted and availabel via a flag, but at the same time
you can use the field's value as it is a normal int for example, and it is
then for example 0.
FB
--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP