Olukayode Oluwole
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.staticbirt hdate = model.birth_dt = Convert.ToDateTime(BirthDa teValue.Te xt);
The Birthdate on screen reads 28-07-2019 (see screen below)
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
The line being flagged above is part the definition below
What is wrong with the way i have passed the date field and how do I resolve this error ?
Thanks
Olukay
EmployeeDetails.staticbirt
The Birthdate on screen reads 28-07-2019 (see screen below)
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
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;
}
What is wrong with the way i have passed the date field and how do I resolve this error ?
Thanks
Olukay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tried Decimal.Parse and it worked
Thanks
Olukay
Thanks
Olukay
Great! Thanks for the feedback.
ASKER
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