首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

生活所迫在来问个有关问题。哎。都不好意思了

2012-02-21 
生活所迫在来问个问题。。哎。都不好意思了ServerErrorin/Application.------------------------------------

生活所迫在来问个问题。。哎。都不好意思了
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 ");

请高手指点。。

[解决办法]
dt.Rows[0][5] 看一下这个值 没空值

[解决办法]
if(dt.Rows[0][5]==null || dt.Rows[0][5]== " ")
{
txtSp_time.Text= " ";
}
else
{
txtSp_time.Text= Convert.ToDateTime(dt.Rows[0][5]).ToString( "yyyy-MM-dd ");
}
[解决办法]
先判断一下dt.Rows[0][5]是不是为空。
如果格式不正确也会报错的

[解决办法]
加了 一个问号。。问高手这个是什么原因
==============================
顶不知道,
[解决办法]
学习

热点排行