本文介绍了搜索记录时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以拨打这是什么类型的错误.?

这里出现错误

hi can any one telmme what type of error is this.?

here am getting error

 protected void grdFaculty_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
//for sum m getting error
            sum = sum + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "NoOfDuties"));//in this line m getting error
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label obj = (Label)e.Row.FindControl("Sum");
            obj.Text = Convert.ToString(sum);
        }
    }

like
Object cannot be cast from DBNull to other types.
can any one suggest me?

推荐答案

DataBinder.Eval(e.Row.DataItem, "NoOfDuties")



相反:



Instead:

if (! DBNull.Value.Equals(DataBinder.Eval(e.Row.DataItem, "NoOfDuties"))
    sum = sum + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "NoOfDuties"));



此处 [ ^ ]

在这里,我假设DBNull表示该字段为0.



More information is available here[^]

Here, I have assumed that DBNull means 0 for this field.


这篇关于搜索记录时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-02 15:53