zoukankan      html  css  js  c++  java
  • LINQ to DataSet

           

      DataSet ds = getDataset();

        //第一种方法
            //var matches = from p in ds.Tables["products"].AsEnumerable()
            //              where p.Field<decimal>("UnitPrice") > 10
            //              select p;
            //gvProducts.DataSource = matches.AsDataView();


            //第二种方法
            var matches = from p in ds.Tables["products"].AsEnumerable()
                          where p.Field<decimal>("UnitPrice") > 10
                          select new { pid = p.Field<int>("ProductId"), pname = p.Field<string>("ProductName"), price = p.Field<decimal>("UnitPrice") };
            //当在LINQ表达式中使用"投影"后,则可不调用AsDataView()方法。
            gvProducts.DataSource = matches;
            gvProducts.DataBind();

    ====================LINQ to DataSet 处理空值问题=====================

     DataSet1 ds = new DataSet1();
            DataSet1TableAdapters.EmployeesTableAdapter empsda = new DataSet1TableAdapters.EmployeesTableAdapter();
            empsda.Fill(ds.Employees);
            var matches = from emp in ds.Employees
                          where emp.Field<int?>("reportsto") != null && emp.Field<string>("Region") != null
                          select emp;
            gvProducts.DataSource = matches;
            gvProducts.DataBind();

  • 相关阅读:
    SQL语句
    POJ2586——Y2K Accounting Bug
    POJ1328——Radar Installation
    POJ2965——The Pilots Brothers' refrigerator
    SDIBT2666——逆波兰表达式求值
    POJ1753——Flip Game
    Python全栈开发-有趣的小程序
    跑马灯效果、jquery封装、$.fn和$.extend方法使用
    js 实现浏览器全屏效果
    百度地图点聚合功能如何提高性能
  • 原文地址:https://www.cnblogs.com/zxhoo/p/1884719.html
Copyright © 2011-2022 走看看