Well, besides the obvious problem that everyone was talking about if (Convert.ToDateTime(cmd).CompareTo(System.DateTime.Now) < 0) //need to use date instead of cmd , the code contains an anti-template that uses too general catch blocks.
The code captures the exception for handling IO exceptions. But what if there are other types of exceptions? I'm starting to suspect that for some reason Convert.ToDateTime throws an error that is swallowed by the catch statement, which, in your opinion, only catches IO exceptions. In fact, it will catch any exception, including a possible FormatException that may be FormatException by calling Convert.ToDateTime .
But it could be a SqlException , as I will explain below:
This line also has invalid SQL:
MySqlCommand cmd = new MySqlCommand("SELECT Date FROM fundamentals of is WHERE ChapNo=Chapter 1", connection);
I think it should be:
MySqlCommand cmd = new MySqlCommand("Select Date from fundamentals where ChapNo='Chapter 1'", connection); //that is, if ChapNo is a STRING/TEXT!
executing this command will result in an error that you cannot detect due to your catch statement. You should make your withdrawal statements as specific as possible.
source share