use*_*low 0 c# asp.net datetime message
我有一个搜索功能(由我的前任编写),它将日期范围,ID,可用程序作为输入,并在gridview中显示结果.该功能在大多数情况下工作正常(我已经测试过)但是对于我的应用程序的一个用户,它给出了此错误消息.我无法自己重现此错误以便修复它.不知道出了什么问题!
你们能帮忙吗?
抛出了类型'System.Web.HttpUnhandledException'的异常.System.FormatException:String未被识别为有效的DateTime.在System.DateTimeParse.Parse(String s,DateTimeFormatInfo dtfi,DateTimeStyles样式)的
位于System.Convert.ToDateTime(字符串值)的APP_ViewFollowupWorkload.GetFilterString()在d:\ SharedServices\APP\ViewFollowupWorkload.aspx.cs:第1415
行在APP_ViewFollowupWorkload .Page_Load(对象发件人,EventArgs e)在d:\ SharedServices\APP\ViewFollowupWorkload.aspx.cs:线268
在错误帮助(IntPtr的FP,对象O,对象吨,EventArgs的)
在系统
位于System.Web.UI.Page的System.Web.UI.Control.LoadRecursive()的System.Web.UI.Control.OnLoad(EventArgs e)
中的.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)
. ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在System.Web.UI.Page.HandleError(例外五)
在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在System.Web.UI.Page.ProcessRequest(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在System.Web.UI.Page.ProcessRequest()
在System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext的上下文)在System.Web.UI.Page.ProcessRequest(HttpContext的上下文)
在ASP.app_viewfollowupworkload_aspx.ProcessRequest( HttpContext上下文)在C:\ WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\bad754dd\a11f74ff\App_Web_viewfollowupworkload.aspx.ae7ca9bd.uwyek3vs.0.cs:
System.Web中的第0行.
System.Web.HttpApplication.ExecuteStep中的HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()(IExecutionStep step,Boolean&completedSynchronously)
这是生成错误的.cs文件代码:
if (txtDateTo.ToString() != string.Empty)
{
if (txtDateTo.ToString().Length > 2)
strFilter = strFilter + " AND submission_date <= ''" + Convert.ToString(Convert.ToDateTime(txtDateTo.ToString()) + new TimeSpan(1, 0, 0, 0)) + "''";
}
Run Code Online (Sandbox Code Playgroud)
该错误表明值的传递txtDateTo不是有效的DateTime- 比方说32/11/2011.
您可以使用其中一个DateTime.TryParse重载将代码更改为不会引发异常的代码.这不会解析无效值,但会避免抛出异常 - 您仍需要确定在这种情况下要执行的操作.
| 归档时间: |
|
| 查看次数: |
4040 次 |
| 最近记录: |