My ASP.net Class works fine except for one data field

Hello I created a class in asp.net.  I ran a stored procedure where the class was able to pull all of the data with guid user id as the data parameter.  All of the data fields that come back except for one data field which is a dateandtime field.  Here is the code that I used to retrieve the data from a stored procedure:

Please note, I commented out the first Result which is the desired return value of all fields from a database but I opened the new result with a few select fields to test the data.

 public HRProfile GetWithoutProfileImages(Guid hrprofileid)
        {
            HRProfile Result = new HRProfile();

            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand("spGetHRProfileByProfileIdWithoutImages", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    Result.HRProfileId = hrprofileid;

                    SqlParameter sqlparamaccountid = new SqlParameter("@HRProfileId", Result.HRProfileId);

                    sqlparamaccountid.Value = hrprofileid;

                    sqlparamaccountid.Direction = ParameterDirection.Input;

                    command.Parameters.Add(sqlparamaccountid);

                    SqlDataReader ThisReader = command.ExecuteReader(CommandBehavior.CloseConnection);

                    while (ThisReader.Read())
                    {
                        System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;

                        //Result = new HRProfile(hrprofileid, new Guid(ThisReader["UserId"].ToString()), Convert.ToInt32(ThisReader["ProfileTypeId"].ToString()), ThisReader["ProfileDisplayName"].ToString(), Convert.ToDateTime(ThisReader["BirthDay"].ToString()), ThisReader["FirstName"].ToString(), ThisReader["LastName"].ToString(), ThisReader["Address"].ToString(), ThisReader["City"].ToString(), ThisReader["State"].ToString(), ThisReader["Zip"].ToString(), ThisReader["Region"].ToString(), ThisReader["Country"].ToString(), Convert.ToBoolean(ThisReader["IsDefaultPicture"].ToString()), Convert.ToInt32(ThisReader["Gender"].ToString()), Convert.ToDateTime(ThisReader["MemberSince"].ToString()), Convert.ToBoolean(ThisReader["IsActive"].ToString()), Convert.ToBoolean(ThisReader["IsOnline"].ToString()), ThisReader["MobilePhone"].ToString(), ThisReader["HomePhone"].ToString(), ThisReader["SocialSecurityNumber"].ToString(), ThisReader["PassportNumber"].ToString(), Convert.ToDateTime(ThisReader["PassportExpirationDate"].ToString()), ThisReader["CountryIssuingPassport"].ToString(), ThisReader["SecurityClearanceAndType"].ToString(), ThisReader["NameTitle"].ToString());
                        Result = new HRProfile(hrprofileid, new Guid(ThisReader["UserId"].ToString()), Convert.ToInt32(ThisReader["ProfileTypeId"].ToString()), ThisReader["ProfileDisplayName"].ToString(), Convert.ToDateTime(ThisReader["BirthDay"].ToString()), ThisReader["FirstName"].ToString(), ThisReader["LastName"].ToString(), ThisReader["Address"].ToString(), ThisReader["City"].ToString(), ThisReader["State"].ToString(), ThisReader["Zip"].ToString(), ThisReader["Region"].ToString(), ThisReader["Country"].ToString(), Convert.ToInt32(ThisReader["Gender"].ToString()), (Convert.ToDateTime(ThisReader["MemberSince"].ToString())));
                    }
                }

            }

            return Result;
        }

Open in new window

VBBRettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VBBRettAuthor Commented:
The field that I am having a problem with when it is returned is the following field:

(Convert.ToDateTime(ThisReader["MemberSince"].ToString());
0
David ToddSenior DBACommented:
Hi,

What form is the string? mm/dd/yyyy or yyyy-mm-dd for instance?

Its quite possible that .ToString() is returning one form, and the convert is expecting the other.

Regards
  David
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RouchieCommented:
What exactly is the problem?  You've only said that a field is 'not working'.
I assume that all dates have to have a value in the database, otherwise you must check for NULL because you cannot cast a null value to DateTime
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.