Presumably - and we can;t check - the error is coming on this line:
DateTime dtEvent=(DateTime)dr["appointmentdate"];
Since it is right in the middle of your "my error is here" bit. (In future, tell us exactly which line it is)
And teh only cast there is to DateTime - which implies that whatever you have in your
appointmentdate
column is not a type that can be cast to a DateTime value. And that probably means that the source column in your database is not a DATE or DATETIME column, since only those values will cast to DateTime.
So start with your DB, and look at your table definition. At a guess, you are storing dates in VARCHAR or NVARCHAR columns, and that is what is causing the problem.
If so, the solution is simple: store data in appropriate data types. DateTime values go in DATE or DATETIME, int32 values in INT, and so on. Storing things in strings may seem really easy - but it's a PITA to work with later!