Entity Framework stored procedure error with DateTime
Hi I am getting an error 'Conversion failed when converting date and/or time from character string' When calling a stored procedure using EF4.
I am passing from my c# 2 DateTimes like this
@FromDate='2010-11-10 12:30:14.2558729' @ToDate= '2010-11-10 12:30:15.1169590'
How can I prevent this error?
if I do the followin开发者_如何学JAVAg in my UI it works
FromDate = new DateTime (SelectedFromDate.Year,SelectedFromDate.Month,SelectedFromDate.Day),
ToDate = new DateTime(SelectedToDate.Year, SelectedToDate.Month, SelectedToDate.Day),
Thanks for any suggestions
Reduce the number of digits on the fractional seconds to three. Try it out...
What you are trying to do:
select convert(datetime,'2010-11-10 12:30:14.2558729')
-- ^^^^^^^
OUTPUT:
-----------------------
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string.
Using only 3 decimal digits:
select convert(datetime,'2010-11-10 12:30:14.255')
-- ^^^
OUTPUT:
-----------------------
2010-11-10 12:30:14.257
(1 row(s) affected)
精彩评论