Most likely, it's not the code: it's the input you are passing to the code!
I assume the error occurs on this line:
Command.Parameters.Add("@Permitdate", SqlDbType.DateTime).Value = DateTime.ParseExact(_permitdate, "yyyy/MM/dd", CultureInfo.InvariantCulture);
And I'd start by looking at exactly what you are handing it in the form of
_permitdate
- if it doesn't
exactly match the format you specify:
yyyy/MM/dd
then you will get the exception. And that includes any other characters in the string!
So use the debugger: put a breakpoint on the line, and when your code hits it, look at what the variable contains. If it doesn't match exactly, then you need to look at where it came from!