System.InvalidCastException:无法将对象从DBNull强制转换为其他类型。 [英] System.InvalidCastException: Object cannot be cast from DBNull to other types.?

查看:76
本文介绍了System.InvalidCastException:无法将对象从DBNull强制转换为其他类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
任何人都可以帮我解决这个问题..

我不是要解决这个问题



这里是我的代码

十进制grdTotal = 0;

<前lang =cs> 受保护 void GridView1_RowDataBound1( object sender,GridViewRowEventArgs e)
{


if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal rowTotal = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, tsMonday));

grdTotal = grdTotal + rowTotal;

}

if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl =(Label)e.Row.FindControl( lblTotal);
lbl.Text = grdTotal.ToString( c);
}




}







十进制rowTotal = Convert.ToDecimal 



这一行收到错误..



请建议我..

谢谢你

解决方案

请参考这个并尝试写格式就像他们说的那样 -



http:// forums。 asp.net/t/1162142.aspx/1 [ ^ ]

hi can any one help me to solve this..
am not trying to solve this

here is my code
decimal grdTotal=0;

protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {


        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            decimal rowTotal = Convert.ToDecimal
                (DataBinder.Eval(e.Row.DataItem, "tsMonday"));

            grdTotal = grdTotal + rowTotal;

        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lbl = (Label)e.Row.FindControl("lblTotal");
            lbl.Text = grdTotal.ToString("c");
        }




    }




decimal rowTotal = Convert.ToDecimal


this line am getting error..

please suggest me..
thank you

解决方案

Refer this and try to write format like they said-

http://forums.asp.net/t/1162142.aspx/1[^]


这篇关于System.InvalidCastException:无法将对象从DBNull强制转换为其他类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆