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

  • 相关阅读:
    poj 1392 Ouroboros Snake
    poj 1780 Code
    poj 2513 Colored Sticks
    ZOJ 1455 Schedule Problem(差分约束系统)
    poj 3169 Layout (差分约束)
    ZOJ1260/POJ1364国王(King)
    poj 1201/zoj 1508 intervals 差分约束系统
    zoj 2770 Burn the Linked Camp (差分约束系统)
    构造函数和析构函数
    PHP面向对象——静态属性和静态方法
  • 原文地址:https://www.cnblogs.com/Jeremy2001/p/9124290.html
Copyright © 2011-2022 走看看