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");请高手指点。。
解决方案 »
- eWebeditor修改新闻的问题.net
- 大家来看啊。。出了奇怪事了(MVC)
- js如果得到服务器控件的值?
- ASP.NET脚本注册问题,急急急急急急————————在线等待
- 请问在插入记录之前,.net中获得SQLSERVER记录自动编号的方法(讨论)
- 在WEB页面中怎样嵌入Word文档在线编辑 在线等
- 谁能帮帮我(DataGrid控件)!!!!!
- 散分!请问大家好几个人做项目时,程序是怎么样调试的?程序员之间是怎么协调的?
- 诚征.net网站程序高手兼职开发网站
- 2个ASPX文件 一个当前台 一个当后台 没有跳转的时候 前台怎么调用后台TextBox的Text
- 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");