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();

  • 相关阅读:
    DataSet生成gb2312编码的xml
    利用SendMessage实现C#进程间通信
    DataSet与Xml之间的转换
    xml解析
    当前时间加指定的几个月
    Excel利用poi导入导出(上)
    mybatis.generator.plugins生成基础类
    Excel利用poi导入导出(下)
    ASP.NET 中的Session统一管理
    太幸福了,没有比我们更开放的网络了!
  • 原文地址:https://www.cnblogs.com/zxhoo/p/1884719.html
Copyright © 2011-2022 走看看