I am using a SqlDataSource object to insert records into a database. I get the error "String was not recognized as a valid DateTime." when I try to pass a datetime variable to the stored procedure. I have limited the problem to my code - it doesn't even make it to the stored procedure, so that's not a problem.
This code is in the Inserting event of the SqlDataSource object:
I have tried this:
e.Command.Parameters["@Start_Time"].Value = Convert.ToDateTime("9/4/2001");
e.Command.Parameters["@Start_Time"].Value = Convert.ToDateTime("9/4/2001 9:54 PM");
and a whole bunch of other combinations, even using DateTime.Parse. This is very awkward because it only has a problem with the Insert method of the SqlDataSource object - again, it doesn't even call the stored procedure at this time, so it isn't a problem with the stored procedure. It errors out before it can even do this!
Converting to datetime should be the easiest task in.NET - have you had a similar problem? Please help! I can't figure it out.