You've got redundant code:
MySqlDataAdap.InsertCommand.Parameters.Add(new MySqlParameter("@Amount", amt));
MySqlDataAdap.InsertCommand.Parameters[0].Value = amt;
Similarly, where you add the second parameter:
MySqlDataAdap.InsertCommand.Parameters.Add(new MySqlParameter("@DatePaid", payDate));
MySqlDataAdap.InsertCommand.Parameters[1].Value = (getUserLevel() == "Lower Level" ? SYSDATE() : depositDate.ToString());
You set the property to
payDate
, then set it again to
SYSTDATE()
or
depositDate.ToString()
so you should decide which of these is correct. Additionally you don't need the
.ToString()
on the final term as the value is an object not a string. As far as I'm aware
SYSTDATE()
isn't a c# method so that is suspicious too, my guess is you need to remove that line of code from your description of what it does but I'm not certain.
If, after you've changed you code you are still getting the same error message you need examine the value you are passing in to the date paid parameter. What is currently happening is that the currently date is being passed as a
string
rather than a
datetime
and the framework can't figure out how to transform the string into a .net datetime (this change of string to a different object type is called parsing). You need to work out why the parse is failing. There are lots of reasons this can happen e.g. the date is just invalid "32-Dec-2012", culture plays a part for example when an american formatted date is supplied date where a UK date is expected (e.g. 12/13/2012 for the 13
th December) or even the date being passed is null. In your case I'd google for "
DateTime.Parse
" and actually manually parse the string into a
datetime
object and pass that as the value not its string.