Object cannot be cast from DBNull to other types for Double Data Type

后端 未结 3 538
暗喜
暗喜 2021-01-27 06:39

I am seeing error when there is null value in database for any cell, Object cannot be cast from DBNull to other types. - Asp.net grid view



        
3条回答
  •  死守一世寂寞
    2021-01-27 06:50

    You need to compare you values with DBNull.Value as follow

    protected string PercentageChange(object client_Price, object second_price)
    {
           if(client_price==DBNull.Value)
           {
               .....
           }
           //double price1 = Convert.ToDouble(client_Price);
           //double price2 = Convert.ToDouble(second_price);
           //double percentagechange = ((price1 - price2) / price2) * 100;
           //return percentagechange ;
     } 
    

提交回复
热议问题