I have a masked textbox in my form where the user enters the date as dd/MM/yyyy
and then this value is inserted into a sql server table.
I'm getting the following error when the query is executed:
the conversion of a varchar data type to a datetime data type resulted in an out-of-range value
I have tried many ways and tried to look for similar issues online and tried the fixes/answers but I'm still getting the error.
The error only happens when the 'dd' entered is higher than 12 so i assume that the sql server is taking that value as the MM instead of dd.
Below is what I tried.
What I have tried:
Datetime receivedDate = DateTime.ParseExact(receivedDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
The insert statement is as follows:
string query = "INSERT INTO dateTbl(recD) VALUES('" + receivedDate + "')"