Server Error in '/' Application.
--------------------------------------------------------------------------------Object cannot be cast from DBNull to other types.
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.InvalidCastException: Object cannot be cast from DBNull to other types.Source Error:
Line 37: txtSp_content.Text = dt.Rows[0][3].ToString();
Line 38: txtSp_cost.Text = dt.Rows[0][4].ToString().Trim();
Line 39: txtSp_time.Text= Convert.ToDateTime(dt.Rows[0][5]).ToString("yyyy-MM-dd");
Line 40: ddlSp_xianshi.SelectedValue = dt.Rows[0][6].ToString();
Line 41: }
Source File: f:\usr\cn30120\admin\daili\edit.aspx.cs Line: 39 Stack Trace:
[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToDateTime(IFormatProvider provider) +54
System.Convert.ToDateTime(Object value) +29
admin_daili_edit.Bin(String strsql) in f:\usr\cn30120\admin\daili\edit.aspx.cs:39
admin_daili_edit.Page_Load(Object sender, EventArgs e) in f:\usr\cn30120\admin\daili\edit.aspx.cs:24
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint
他老报 转换这儿出问题 Line 39: txtSp_time.Text= Convert.ToDateTime(dt.Rows[0][5]).ToString("yyyy-MM-dd");请高手指点。。
--------------------------------------------------------------------------------Object cannot be cast from DBNull to other types.
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.InvalidCastException: Object cannot be cast from DBNull to other types.Source Error:
Line 37: txtSp_content.Text = dt.Rows[0][3].ToString();
Line 38: txtSp_cost.Text = dt.Rows[0][4].ToString().Trim();
Line 39: txtSp_time.Text= Convert.ToDateTime(dt.Rows[0][5]).ToString("yyyy-MM-dd");
Line 40: ddlSp_xianshi.SelectedValue = dt.Rows[0][6].ToString();
Line 41: }
Source File: f:\usr\cn30120\admin\daili\edit.aspx.cs Line: 39 Stack Trace:
[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToDateTime(IFormatProvider provider) +54
System.Convert.ToDateTime(Object value) +29
admin_daili_edit.Bin(String strsql) in f:\usr\cn30120\admin\daili\edit.aspx.cs:39
admin_daili_edit.Page_Load(Object sender, EventArgs e) in f:\usr\cn30120\admin\daili\edit.aspx.cs:24
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint
他老报 转换这儿出问题 Line 39: txtSp_time.Text= Convert.ToDateTime(dt.Rows[0][5]).ToString("yyyy-MM-dd");请高手指点。。
解决方案 »
- 复选框回发的问题
- fckeditor 2.6.6的上传问题
- VS中导出EXCEL执行正常,但是一放到IIS上,就出问题,该怎么样查?
- 调用window.onbeforeunload事件,点击翻页事件时,弹出2次窗口?
- 继续散,唉,看样子等下揭帖的时候会收酸了....
- 急请教:用客户端事件检测输入内容合法性。
- 请问怎么从数据库的表中读出规定数目的数据(access)
- 我的.NET工具箱里怎么没有iframe?
- sql server2000连接问题,在线等待
- 菜鸟问题。我用Visual Studio .NET做好了一个ASP.NET的网站,可是发到服务器上确不能运行?
- gridview与detailsview关联,分页后错误该怎么办
- gridview的数据源可以是什么?
{
txtSp_time.Text= "";
}
else
{
txtSp_time.Text= Convert.ToDateTime(dt.Rows[0][5]).ToString("yyyy-MM-dd");
}
如果格式不正确也会报错的
Object cannot be cast from DBNull
=============================================System.Object date = dt.Rows[0][5];
if(System.DBNull.Value != date)
txtSp_time.Text = Convert.ToDateTime(date).ToString("yyyy-MM-dd");