Thanks for all that replied. I did get this working finally last night. I
guess my interpration was the DBNull was the same as "null" in .NET.
Apparently not.
I basically changed the line that read (DateTime?)row["EndDate"] to do a
tenary check:
DateTime? TimeEnd;
TimeEnd = row["TimeEnd"] == DBNull.Value ? null : (DateTime?)row["TimeEnd"];
This seems to work fine and displays as an empty cell when listing in
GridView; which was what I wanted.
Of course, I need to now do the same for TimeStart and any other
SmallDateTime fields I have within SQL that may return NULLs.
This seems like a common mistake that folks would make when using
ObjectDataSource and I'm surprised that there has really been no mention of
this anywhere in the many examples that I've looked at. I guess
trial-and-error and posting in these newsgroups is the only way to figure
these sorts of "opportunities" out.
Now for another question ---
Since I'm creating a type class for all the fields within my DAL that is
returned to my BAL, is there an easy way to create the class?
Currently, I'm doing something like:
private Int16 _JobNum;
private string _Status;
private DateTime? _TimeStart;
private DateTime? _TimeEnd;
private DateTime? _JobName;
Then I do my constructor and the get/set functions...
public Int16 JobNum
{
get { return _JobNum; }
set { _JobNum = value; }
}
If my query in the DAL has 15 fields, it takes a while to create my type
class for this. I'm wondering if I can easily do this thru Visual Studio
or some other product.
Any help or recommendations would be appreciated.
Thanks all!
"Rune B" <ye*******@bingo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Using the nullable DateTime? time doesn't appear to help. Trying to pass
the fields to my Add() collection fails each time... and I changed all
the DateTime references within my type class to use DateTime?.
Looking back at "Elton W" suggestion doesn't make much sense to me. I
mean, even if I verify that it is null or not, then what? I still got
to pass a valid DateTime type to my collection.
I think what he suggested was instead of the very optimistic filling:
(DateTime)row["EndDate"]
you should check whether content is null or not first, (wrap it in a
function)
DateTime? enddate;
object obj = row["EndDate"];
if(obj != null)
enddate = (DateTime);