W
WJ
Hello,
I got an exception telling me that Invalid Casting on a Date field. Here is
what I attempted to do in my Asp.Net app:
1. A class that contains 4 fields called Employee Record (eye), two out of 4
fields are DateTime type. The class name is "eyeClass".
******** Code sample *********
using System;
namespace hr.eye
{
[Serializable]
public class eyeClass
{
private string _LastName;
private string _FirstName;
private DateTime _BirthDate;
private DateTime _HireDate;
public eyeClass()
{
}
public eyeClass
(
string LastName
,string FirstName
,DateTime BirthDate
,DateTime HireDate
)
{
this._LastName=LastName;
this._FirstName=FirstName;
this._BirthDate=BirthDate;
this._HireDate=HireDate;
}
public string LastName {get{return _LastName;}}
public string FirstName {get{return _FirstName;}}
public DateTime BirthDate {get{return _BirthDate;}}
public DateTime HireDate {get{return _HireDate;}}
}
}
On Asp.Net Page Behind code (onReadDataOKClick button): I have the following
codes:
DataSet ds=new DataSet();
Call SqlHelper.FillDataset to extract data into ds; //it returned two
tables with data (one record per table).
//this instruction below attempts to fill "eyeClass" with data retrieved
from DataSet .
//Exception is thrown when any DateField is NULL. (Invalid Casting)
eyeClass eye=new eyeClass(
ds.Tables[0].Rows[0]["LastName"].ToString()
,ds.Tables[0].Rows[0]["FirstName"].ToString()
,(DateTime)ds.Tables[0].Rows[0]["BirthDate"]
,(DateTime)ds.Tables[0].Rows[0]["HireDate"]);
******** Code sample Ended *********
Problem: The exception is thrown on the HireDate because it is NULL and I
need it to be nulled in some cases. I cannot trap the message here with the
TRY/Catch.
My question is: How can I force the application just go ahead to eat the
"exception"... and move on instead of exiting the program completely.
Thanks
John
I got an exception telling me that Invalid Casting on a Date field. Here is
what I attempted to do in my Asp.Net app:
1. A class that contains 4 fields called Employee Record (eye), two out of 4
fields are DateTime type. The class name is "eyeClass".
******** Code sample *********
using System;
namespace hr.eye
{
[Serializable]
public class eyeClass
{
private string _LastName;
private string _FirstName;
private DateTime _BirthDate;
private DateTime _HireDate;
public eyeClass()
{
}
public eyeClass
(
string LastName
,string FirstName
,DateTime BirthDate
,DateTime HireDate
)
{
this._LastName=LastName;
this._FirstName=FirstName;
this._BirthDate=BirthDate;
this._HireDate=HireDate;
}
public string LastName {get{return _LastName;}}
public string FirstName {get{return _FirstName;}}
public DateTime BirthDate {get{return _BirthDate;}}
public DateTime HireDate {get{return _HireDate;}}
}
}
On Asp.Net Page Behind code (onReadDataOKClick button): I have the following
codes:
DataSet ds=new DataSet();
Call SqlHelper.FillDataset to extract data into ds; //it returned two
tables with data (one record per table).
//this instruction below attempts to fill "eyeClass" with data retrieved
from DataSet .
//Exception is thrown when any DateField is NULL. (Invalid Casting)
eyeClass eye=new eyeClass(
ds.Tables[0].Rows[0]["LastName"].ToString()
,ds.Tables[0].Rows[0]["FirstName"].ToString()
,(DateTime)ds.Tables[0].Rows[0]["BirthDate"]
,(DateTime)ds.Tables[0].Rows[0]["HireDate"]);
******** Code sample Ended *********
Problem: The exception is thrown on the HireDate because it is NULL and I
need it to be nulled in some cases. I cannot trap the message here with the
TRY/Catch.
My question is: How can I force the application just go ahead to eat the
"exception"... and move on instead of exiting the program completely.
Thanks
John