0

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; }
}
7
  • The error is explanatory. The value on your tablewsm_View_PurchaseOrderList.TotalValueColumn is null. Commented May 31, 2017 at 2:34
  • how to handle it ? Commented May 31, 2017 at 2:35
  • What is the Data type of TotalValueColumn? You can check if the value is null or not and use 0 if its null. Commented May 31, 2017 at 2:38
  • money-datatype total value col. Commented May 31, 2017 at 2:40
  • TotalValueColumn seems have DBNull value when it assigned to non-null decimal equivalent. Probably certain check against DBNull.Value is possible. Commented May 31, 2017 at 2:44

1 Answer 1

1

Try checking for DBNull like this:

if (Convert.IsDBNull(tablewsm_View_PurchaseOrderList.TotalValueColumn))
{
    return 0.0;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.