Currently I've a string with a date and time. When I show the string it looks like:
2015-06-16 09:17:28 PM
But when I try to put it into the database it's telling me:
Additional information: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
I've to convert the string. So there is now other way!
What's the right way to do this? Obviously the value in database is datetime.
This is my code (I've put it together actually it's from multiple classes):
string time = date + " " + txtTime.Text;
DateTime temp = Convert.ToDateTime(time);
String query ="insert into reserveringen (reserveringId,klantId,medewerkerId,aantalPersonen,begintijd,eindtijd)values(@reserveringId,@klantId,@medewerkerId,@aantalPersonen,@begintijd,@eindtijd)";
SqlCommand comm = sqlCrud.returnSqlCommand(query);
comm.Parameters.AddWithValue("begintijd",temp);
I already googled a lot.... but nothing works.
Thanks
DateTime temp = DateTime.Parse(time);
. – EBrown Jun 16 '15 at 19:30eindtijd
that is the problem, and notbegintijd
? We don't see what you're specifying for that value. (I'm basing the question on the suffix assuming they both mean date :P) – Kritner Jun 16 '15 at 19:34AddWithValue
, if you replacetemp
withDateTime.Now
just as a test. Does that work? – sstan Jun 16 '15 at 19:35temp
. Also, I'm not sure if those params work without the@
. – Henk Holterman Jun 16 '15 at 19:35@reserveringId
. – Kritner Jun 16 '15 at 19:41