Login authentication on my website is based on three parameters of which one is date of birth. A DatePicker is provided to the user to select the Date. The format in which the date is saved in Database is MM/dd/yyyy.
When is check for the authentication the Linq query is not returning any result as the record in Database is in MM/dd/yyyy and the value passed from the view to the controller is in dd/mm/yyyy.Hence im not getting any output.
Below is my code of what I’m doing in controller.
[HttpPost]
public ActionResult Login(LoginTable log)
{
var login = from a in db.LoginTables
where a.DOB== log.DOB
select a;
}
Also I have tried
var login = from a in db.LoginTables
where a.DOB== log.DOB.toString("MM/dd/yyyy")
select a;
but its giving error (No Overload method ‘ToString()’ takes 1 argument)
What can i do?
The reason this is failing is because the LINQ is translated into SQL syntax and there is no equivalent of
ToStringin SQL.Given that
logis a parameter to your method why not simply have: