zoukankan      html  css  js  c++  java
  • dsLinq.Count() 引发了“System.NullReferenceException”类型的异常

    DataTable dt = PurchaseArriveInfoBus.GetPurchaseArriveInfo(companyCD, txtArriveNo, txtTitle, txtProvider);
            XElement dsXML = ConvertDataTableToXML(dt);
            //linq排序
            var dsLinq =
                (order == "ascending") ?
                (from x in dsXML.Descendants("Data")
                 orderby x.Element(orderBy).Value ascending
                 select new DataSourceModel()
                 {
                     ID = x.Element("ID").Value,
                     ArriveNo = x.Element("ArriveNo").Value,
                     Title = x.Element("Title").Value,
                     ProviderID = x.Element("ProviderName").Value,
                     Purchaser = x.Element("Purchaser").Value,
                     ProductNo = x.Element("ProductNo").Value,
                     ProductName = x.Element("ProductName").Value,
                     ColorName = x.Element("ColorName").Value,
                     
                     TotalPrice = x.Element("TotalPrice").Value,
                     ProductCount = x.Element("ProductCount").Value,
                     InCount = x.Element("InCount").Value,
                     DetailID = x.Element("DetailID").Value,
                     UnitName = x.Element("UnitName").Value,
                     JiBenCount = x.Element("JiBenCount").Value,
                     UnitPrice = IsDisplayPrice ? x.Element("UnitPrice").Value : "0.000000"
    
                 })
                          :
                (from x in dsXML.Descendants("Data")
                 orderby x.Element(orderBy).Value descending
                 select new DataSourceModel()
                 {
                     ID = x.Element("ID").Value,
                     ArriveNo = x.Element("ArriveNo").Value,
                     Title = x.Element("Title").Value,
                     ProviderID = x.Element("ProviderName").Value,
                     Purchaser = x.Element("Purchaser").Value,
                     ProductNo = x.Element("ProductNo").Value,
                     ProductName = x.Element("ProductName").Value,
                     ColorName = x.Element("ColorName").Value,
                     
                     TotalPrice = x.Element("TotalPrice").Value,
                     ProductCount = x.Element("ProductCount").Value,
                     InCount = x.Element("InCount").Value,
                     DetailID = x.Element("DetailID").Value,
                     UnitName = x.Element("UnitName").Value,
                     JiBenCount = x.Element("JiBenCount").Value,
                     UnitPrice = IsDisplayPrice ? x.Element("UnitPrice").Value : "0.000000"
                 });
            int totalCount = dsLinq.Count();
    

      dsLinq.Count() 引发了“System.NullReferenceException”类型的异常,其中任何字段都不能为null

  • 相关阅读:
    玩家上线
    小退
    GS发包到MS
    share初始化
    3 水仙花数
    The left-hand side of an assignment must be a variable,代码中使用了中文的字符
    Mac Sublime Text 浏览器 设置快捷键 让html文件在浏览器打开
    2 质数求解
    1 斐波那契的兔子
    18 赛手的名单
  • 原文地址:https://www.cnblogs.com/Jeremy2001/p/9124290.html
Copyright © 2011-2022 走看看