返回null时如何处理空数据

时间:2016-12-28 18:47:38

标签: asp.net-mvc-4 c#-4.0

我有以下代码为我返回数据。如果结果等于“成功”,那么就有数据。我没有得到任何数据     回来,但得到一个空。数据显示在Web网格上,当webgrid看到数据为空时,页面崩溃。

如何从这里处理null?

        public Chemicalsdetails GetChemicalDataGeneratedForMonth(string branchcode, string departmentnumber, string previousMonth, string currentMonth)
            {
                string result = string.Empty;
                result = _chemmeterprocessor.CopyPreviousMonthData(branchcode, departmentnumber, previousMonth, currentMonth);
                Chemicalsdetails objChem = null;

                if (result == "Success")
                {
                    objChem = new Chemicalsdetails();
                    List<Chemicaltransactiondto> objAllData = new List<Chemicaltransactiondto>();
                    objAllData = _chemmeterprocessor.GetAllChemicalEntries(branchcode, departmentnumber, currentMonth);
                    objChem.GetAllChemicalsInformation = objAllData;                
                }
                else
                {
                    Chemicalsdetails objNoData = new Chemicalsdetails();                 
                }

                return objChem; 
            }

1 个答案:

答案 0 :(得分:0)

检索数据后检查为空。

if string1 == string2:
    // do something