|
-
Feb 10th, 2009, 05:33 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0] DBNull
I searched the forums and kinda found a possible solution, but I can't seem to get it to work.
Here is what I have:
Code:
foreach (DataTable dt in ds.Tables)
{
foreach (DataRow dr in dt.Rows)
{
Customer nCustomer = new Customer((int)dr["CustomerID"], (string)dr["LastName"].ToString(), (string)dr["FirstName"].ToString(), (string)dr["MiddleInitial"].ToString(), (string)dr["FullName"].ToString(), (string)dr["DomainUsername"].ToString(), (string)dr["Phone"].ToString(), (string)dr["Fax"].ToString(), (string)dr["Email"].ToString(), (string)dr["Title"].ToString(),
(string)dr["Address"].ToString(), (string)dr["State"].ToString(), (int)dr["ZIPCode"], (string)dr["City"], (int)dr["SectionID"], (int)dr["DivisionID"], (int)dr["Building"], (string)dr["Country"].ToString());
return nCustomer;
}
}
Some values may be null, and I want to be able to pass these as empty objects either string, int, etc to my class Customer. In VB.NET, I could just return Nothing and it wouldn't throw an exception. In C#, passing "null" to a string or int does.
-
Feb 10th, 2009, 06:21 PM
#2
Thread Starter
Hyperactive Member
Re: [2.0] DBNull
I decided to create 2 functions, one for data I knew was a string, and the other for integers. If the string is null, it returned string.Empty() and if the Integer was DBNull, it returned null. (I changed it from int to int?)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|