2017-02-22 136 views
0
public FeeDetails GetFeeDetails(string admissionno) 
{ 
    var feedetails = from f in db.FeeDetails select f; 

    FeeDetails feedetail = feedetails.Where(f => f.AdmissionNo == admissionno).FirstOrDefault(); 
    FeeDetails feedetailfinal = new FeeDetails(); 

    feedetailfinal.Fee1 = feedetail.Fee1.ToString() != null ? Convert.ToInt32(feedetail.Fee1.ToString()) : 0; 
    feedetailfinal.Fee2 = feedetail.Fee2.ToString() != null ? Convert.ToInt32(feedetail.Fee2.ToString()) : 0; 
    feedetailfinal.Fee3 = feedetail.Fee3.ToString() != null ? Convert.ToInt32(feedetail.Fee3.ToString()) : 0; 
    feedetailfinal.Fee4 = feedetail.Fee4.ToString() != null ? Convert.ToInt32(feedetail.Fee4.ToString()) : 0; 
    feedetailfinal.Fee5 = feedetail.Fee5.ToString() != null ? Convert.ToInt32(feedetail.Fee5.ToString()) : 0; 


    return feedetailfinal; 
} 
+0

確定'feedetail'沒有'null'? – Mairaj

+0

把一個檢查'if(feedetail!= null)'然後訪問它的值。 – Mairaj

+2

哪一行你得到這個錯誤? – A3006

回答

0

我相信每個行應該是這樣的:

if(feedetail != null) 
{ 
    feedetailfinal.Fee1 = feedetail.Fee1 != null 
         ? Convert.ToInt32(feedetail.Fee1) 
         : 0; 
    //other lines 
} 
+0

對於所有記錄,我將返回0,所以我使用: if(feedetail!= null) { feedetailfinal .F1 = feedetail.Fee1; feedetailfinal.Fee2 = feedetail.Fee2; feedetailfinal.Fee3 = feedetail.Fee3; feedetailfinal.Fee4 = feedetail.Fee4; } return feedetailfinal; – Grewal

相關問題