G
Greg
I have a method that accepts some DateTime types. For example:
UserDetails(int userID, string userName, datetime hireDate)
{
this.UserID = userID;
this.UserName = userName;
this.HireDate = hireDate;
}
Now, I'm creating a UserDetails Object by passing the properties as.
UserDetails user;
user = new UserDetails(UserID.Text, UserName.Text, HireDate.Text)
Here's my problem.
When i start all of these fields may or may not contain null values. What I
do for the UserName.Text is check to see if it equals System.DBNull.Value and
if it does I set a temp variable to empty.string.
Now, I need to check the value of the HireDate. If the HireDate.Text equals
System.DBNull.Value then I set a DateTime variable to null. Now, this is the
problem i'm having. I can't set my temp dteHireDate variable to null or
actually empty. I can't send a null value to my method.
This type of situation is actually a very frustrating thing for me because I
have methods that I pass 20 values to and I don't know if the value in my
controls will be null or not. Thus, I must check for each variable to make
sure my method doesn't crash. So, I have two questions.
1. How can I set a DateTime variable to an empty string or some value that I
can pass to a method that isn't equal to null.
2. Is there some better way for me to handle the whole problem of passing
null values to a method. Right now, I'm setting the default value to most of
my fields in SQL Server to Space(1) or one space. This doesn't seem right to
me, but it's the only way I can get moving along without having errors all
the time. I'd prefer to save the NULL values instead.
Thanks.
UserDetails(int userID, string userName, datetime hireDate)
{
this.UserID = userID;
this.UserName = userName;
this.HireDate = hireDate;
}
Now, I'm creating a UserDetails Object by passing the properties as.
UserDetails user;
user = new UserDetails(UserID.Text, UserName.Text, HireDate.Text)
Here's my problem.
When i start all of these fields may or may not contain null values. What I
do for the UserName.Text is check to see if it equals System.DBNull.Value and
if it does I set a temp variable to empty.string.
Now, I need to check the value of the HireDate. If the HireDate.Text equals
System.DBNull.Value then I set a DateTime variable to null. Now, this is the
problem i'm having. I can't set my temp dteHireDate variable to null or
actually empty. I can't send a null value to my method.
This type of situation is actually a very frustrating thing for me because I
have methods that I pass 20 values to and I don't know if the value in my
controls will be null or not. Thus, I must check for each variable to make
sure my method doesn't crash. So, I have two questions.
1. How can I set a DateTime variable to an empty string or some value that I
can pass to a method that isn't equal to null.
2. Is there some better way for me to handle the whole problem of passing
null values to a method. Right now, I'm setting the default value to most of
my fields in SQL Server to Space(1) or one space. This doesn't seem right to
me, but it's the only way I can get moving along without having errors all
the time. I'd prefer to save the NULL values instead.
Thanks.