简体   繁体   中英

db null coming in property asp.net

i am getting error in the code getting error The value for column 'TotalValue' in table 'wsm_View_PurchaseOrderList' is DBNull.

error image

public decimal TotalValue {
    get {

        try {
            if (object.ReferenceEquals(tablewsm_View_PurchaseOrderList.TotalValueColumn, DBNull.Value)) {
                return 0.0;
            } else {
                return Convert.ToDecimal(this(this.tablewsm_View_PurchaseOrderList.TotalValueColumn));
            }

        } catch (System.InvalidCastException e) {
            throw new global::System.Data.StrongTypingException("The value for column 'TotalValue' in table 'wsm_View_PurchaseOrderList' is DBNull" + ".", e);
        }
    }
    set { this(this.tablewsm_View_PurchaseOrderList.TotalValueColumn) = value; }
}

Try checking for DBNull like this:

if (Convert.IsDBNull(tablewsm_View_PurchaseOrderList.TotalValueColumn))
{
    return 0.0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM