Just one line I spotted tells me that you don't understand what are you doing, in principle:
DateTime dat = DateTime.Parse(date.ToString());
Even before seeing the declaration of
data
(your naming style is a separate song), this becomes clear. If it was
DateType
, there is no sense to converted it to string and parse back, but if it's string, there is no sense in getting
ToString
from something which is already a string. Looking for the declaration, we see that it's declared as string. OK, you are not ready to write what you are writing.
And the exception is because the string cannot be interpreted as
DateTime
. If, for example, the input string is "1-2 blah-blah", the parse would fail, isn't that natural? You could find out what really happens if you executed it under the debugger.
By the way, it's not nice to ask about exception not telling us in what line it was thrown.
—SA