Hi all,
When retrieving data from the database I use the following method:
owner.Fax = (string) data["Fax"];
(where data is a SqlDataReader)
However, if data["Fax"] is null, it generates a Cast Exception, id rather not have to put if statements all over each retrieval. So whats the "standard" way of achieving this?
I guess I could put a try { } catch() around it to silence the exception, but would it then not move onto the next statement?
e.g.
try
{
wner.OwnerID = (int) data["OwnerID"];
owner.Title = (string) data["Title"];
owner.Forename = (string) data["Forename"];
owner.Surname = (string) data["Surname"];
owner.Telephone = (string) data["Telephone"];
}
catch(SomeException ex) { // do nothing }
I also thought about putting the null handling in the properties of the owner class, but that would mean each property would have to be of type object would it not?
Id appreciate anyones advice on this,
Thanks,
Matt.
When retrieving data from the database I use the following method:
owner.Fax = (string) data["Fax"];
(where data is a SqlDataReader)
However, if data["Fax"] is null, it generates a Cast Exception, id rather not have to put if statements all over each retrieval. So whats the "standard" way of achieving this?
I guess I could put a try { } catch() around it to silence the exception, but would it then not move onto the next statement?
e.g.
try
{
wner.OwnerID = (int) data["OwnerID"];
owner.Title = (string) data["Title"];
owner.Forename = (string) data["Forename"];
owner.Surname = (string) data["Surname"];
owner.Telephone = (string) data["Telephone"];
}
catch(SomeException ex) { // do nothing }
I also thought about putting the null handling in the properties of the owner class, but that would mean each property would have to be of type object would it not?
Id appreciate anyones advice on this,
Thanks,
Matt.