Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

Why am i having errors passing a screen date field into other variables defined as dates ?

I have a line in my c# application where i pass a Date variable into my model and a defined static class variable (see below)

EmployeeDetails.staticbirthdate = model.birth_dt = Convert.ToDateTime(BirthDateValue.Text);

The Birthdate  on screen reads  28-07-2019 (see  screen below)

User generated image
When passing the date variable to both the model and static class variable which are both defined as date

the values now read 0001/01/01 and not the actual value on screen and i end up with an error

while still trying  to read the date field into those variables.

See Error scree below

User generated image
The line being flagged above is part the definition below

{
            PersonnelModel model = new PersonnelModel();
            EmployeeDetails.staticstaffno = model.type_app = TypeAppValue.Text;
            EmployeeDetails.staticstaffno = model.staff_no = StaffNoValue.Text;
            EmployeeDetails.staticsurname = model.surname = SurnameValue.Text;
            EmployeeDetails.staticfirstname = model.firname = FirstNameValue.Text;
            EmployeeDetails.staticmidinit = model.midinit = MidInitValue.Text;
            EmployeeDetails.staticaddressline1 = model.home_add = AddressLine1Value.Text;
            EmployeeDetails.staticaddressline2 = model.home_add2 = AddressLine2Value.Text;
            EmployeeDetails.staticaddressline3 = model.home_twn = AddressLine3Value.Text;
            EmployeeDetails.staticphoneno = model.offic_phn = PhoneNoValue.Text;
            EmployeeDetails.staticbirthdate = model.birth_dt = Convert.ToDateTime(BirthDateValue.Text);
            EmployeeDetails.staticemployeddate = model.empl_dt = Convert.ToDateTime(EmployedDateValue.Text);
            EmployeeDetails.staticstaffstatus = model.salesstaff= SalesStaffValue.Text;
}

Open in new window


What is wrong with the way i have passed the date field and how do I resolve this error ?

Thanks  

Olukay
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Olukayode Oluwole

ASKER

Thanks for the lead. It worked for the date fields
but i have  the same issue with my decimal fields
I tried  Parse  not ParseExact (for decimal field)   since this has no specific format but it was flagged

I think I got  the specific culture statement wrong.  Apart from telling me the specific syntax
for decimals can you please give me a guide on where to get these culture statements

Thanks

Olukay
Tried  Decimal.Parse and it worked

Thanks

Olukay
Great! Thanks for the feedback.