本文介绍了无法将对象从DBNull强制转换为显示的其他类型错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的代码就是这个我不知道我的错误,请帮助我。 Hi,My code is this i dono what's my error, Please help me.decimal getTotalValue(GridView view, int listSourceRowIndex) { decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Each")); //Object cannot be cast from DBNull to other types decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity")); decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "TaxPercentage")); return unitPrice * quantity * (1 - discount); } private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { GridView view = sender as GridView; if (e.Column.FieldName == "Totalototal" && e.IsGetData) e.Value = getTotalValue(view, e.ListSourceRowIndex); } 提前致谢。Thanks in advance.推荐答案 string value = view.GetListSourceRowCellValue(listSourceRowIndex, "Each") +"" ; decimal unitPrice; decimal.TryParse(value, out unitPrice); decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Each").Value); i没有拥有权tp创建一个包含GridVi的项目现在。 所以我只需要猜测。i have no possebilitys tp create a project which contains a GridView right now.so i just have to guess. 这篇关于无法将对象从DBNull强制转换为显示的其他类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 02:50