这是我写的一段
amount=Convert.ToDecimal((dv_grid.Rows[i].Cells["pro_amount"].Value == null ? "0" : dv_grid.Rows[i].Cells["pro_amount"].Value.ToString());如果pro_amount为NULL,则amount值为“0”,否则为dv_grid.Rows[i].Cells["pro_amount"].Value.ToString()).现在我要想实现:
如果pro_amount为NULL或为“”,则amount值为“0”,否则为dv_grid.Rows[i].Cells["pro_amount"].Value.ToString()),

解决方案 »

  1.   

    amount = string.IsNullOrEmpty(dv_grid.Rows[i].Cells["pro_amount"].Value as string)?0:Convert.ToDecimal(dv_grid.Rows[i].Cells["pro_amount"].Value);
      

  2.   

    直接在sql语句里case when判断
      

  3.   

    string value= dv_grid.Rows[i].Cells["pro_amount"].Value as string;  //加这句,如果直接用string.isNullorEmpty(dv_grid.Rows[i].Cells["pro_amount"].Value.ToString())当pro_amount值为null时会出错
    amount=Convert.ToDecimal( string.isNullorEmpty(value) ? "0" : value);
      

  4.   

    dv_grid.Rows[i]对象是否为空要判断吗?