搜索记录时出错 [英] error for searching a record

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

问题描述

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

这里出现错误

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?

推荐答案

我假设您的语法正确.下面的行返回您要转换为Int32的DBNull.

I am assuming your syntax is correct. The line below returns DBNull which you are trying to cast to Int32.

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"));



此处 [



More information is available here[^]

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


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

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