SmartDate and SafeDataReader explanation

SmartDate and SafeDataReader explanation

Old forum URL: forums.lhotka.net/forums/t/2159.aspx


gderoeck posted on Wednesday, January 17, 2007

I've read the book pretty thoroughly and am still a little fuzzy as to the functionality and benefits of these two things.  Can anyone expand on what the benefits are for both?  I apologize for my lack of understanding...........  Thank you in advance!

-Greg

RockfordLhotka replied on Wednesday, January 17, 2007

SmartDate is a date type that has two primary purposes:

  1. Support binding to a TextBox or equivalent, while still acting like DateTime
  2. Support the concept of an "empty" date, which is different from a null date in that a null date is, by definition, an undefined value, while an empty date is defined as being specifically empty (and thus can be compared to a real date)

SafeDataReader is a wrapper for any data reader object, and it exists to remove null values. If your database allows nulls in some columns where you really don't need them, then SafeDataReader is an easy way to read from those tables without having to manually de-null all the values.

gderoeck replied on Wednesday, January 17, 2007

Rocky, thank you - that helps a lot.

I look forward to meeting you in Denver this coming Monday!  I'll be at the meeting you'll be speaking at.

Thanks again!

-Greg

Jimbo replied on Thursday, January 18, 2007

if you are not using a DataReader but instead processing a generic datatable/datarow result set,  for example,  then the same principles as SafeDataReader can be applied with inline shared functions that convert null fields to empty strings or integer defaults or nullable(of) etc and vica versa.


mroiter replied on Tuesday, January 23, 2007

I use SafeDataReader very often in my Business Object Layer.

It is convinient for me to log Column Name and Position when InvalidCastException occures in any of its Getxxx(int) methods. So I created derived class SafeDataReader2 and overrided methods that incapsulate additional info into my custom exception:

Public Overrides Function GetInt32(ByVal i As Integer) As Integer

Try

Return MyBase.GetInt32(i)

Catch invCastException As InvalidCastException

Throw New DataReaderInvalidCastException("InvalidCastException", invCastException, i,GetName(i))

End Try

I found that Getxxx(string) methods of SafeDataReader are not overridable. Is there some particular reason that prevents these methods from being overridable?

Thanks a lot in advance,

Michael

 

 

 

david.wendelken replied on Tuesday, January 23, 2007

If you like using SmartDate after you use it a bit, check out the CSLA Contrib project, there are other Smart... classes to use also.

Copyright (c) Marimer LLC