我正在开发一个具有DateTime字段的项目。使用WebMatrix和Razor保存日期时间
其中我使用jQuery为用户选择日期格式“dd/MM/yyyy”,考虑到日期不是必填字段。
如何保存WebMatrix和Razor中不需要的日期时间字段?
我试图做这样的事情:
I put only the code which I think is important to complete the code can be found here
@{
//Get data
string TaskForecastCompletion= Request["txtForecastCompletion"];
string TaskCompletedIn= Request["txtCompletedIn"];
DateTime dtForecastCompletion = default(DateTime);
if (!Request["txtForecastCompletion"].IsEmpty() && !DateTime.TryParse(Request["txtForecastCompletion"], out dtForecastCompletion))
{
ModelState.AddError("PrevisaoFinalizacao", "Data de previsão de finalização é inválida. Formato: dd/mm/aaaa");
}
sql = @"update Tasks set Title = @0 ,Description = @1 ,ProjectID = @2 ,ForecastCompletion = @3 ,RequestBy = @4 ,CompletedIn = @5 ,Modified = getdate() ,Priority = @6 where ID = @7";
db.Execute(sql, TaskTitle,TaskDescription, ProjectID, dtForecastCompletion, TaskRequestBy, dtTaskCompletedIn, TaskPriority, TaskID);
}
错误试图改变
An overflow occurred while converting to datetime. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlServerCe.SqlCeException: An overflow occurred while converting to datetime.
Source Error:
Line 62: { Line 63:
sql = @"update Tasks set Title = @0 ,Description = @1 ,ProjectID = @2 ,ForecastCompletion = @3 ,RequestBy = @4 ,CompletedIn = @5 ,Modified = getdate() ,Priority = @6 where ID = @7"; Line 64:
db.Execute(sql, TaskTitle,TaskDescription, ProjectID, dtForecastCompletion, TaskRequestBy, dtTaskCompletedIn, TaskPriority, TaskID); Line 65:
} Line 66:
请在代码块中发布错误而不杀死换行符。 – SLaks 2011-02-28 14:45:18