zoukankan      html  css  js  c++  java
  • 对DataTable的DataRow做group

       1:  public void DataSetLinq41()
       2:  {
       3:      var words4 = testDS.Tables["Words4"].AsEnumerable();
       5:      var wordGroups =
       6:          from w in words4
       7:          group w by w.Field<string>("word")[0] into g
       8:          select new { FirstLetter = g.Key, Words = g };
      10:      foreach (var g in wordGroups)
      11:      {
      12:          Console.WriteLine("Words that start with the letter '{0}':", g.FirstLetter);
      13:          foreach (var w in g.Words)
      14:          {
      15:              Console.WriteLine(w.Field<string>("word"));
      16:          }
      17:      }
      18:      Console.ReadLine();
      19:  }
      20:   
      21:   
      22:  private static DataTable CreateWords4Table()
      23:  {
      24:      string[] words = { "blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese" };
      25:      DataTable table = new DataTable("Words4");
      26:      table.Columns.Add("word", typeof(string));
      27:   
      28:      foreach (string word in words)
      29:      {
      30:          table.Rows.Add(new object[] { word });
      31:      }
      32:      return table;
      33:  }
      34:   
      35:  DataSetLinq41();
  • 相关阅读:
    win7 IIS配置及设置
    JS高效关键字搜索转
    CLR读书笔记第四章 类型基础
    SQL语句执行顺序
    JS常用方法转
    js 设置url参数转
    随机生成 字体大小转
    jquery获得select option的值 和对select option的操作转自(紫寒)
    前端开发者基本要求转
    2 Request对象的一些属性等
  • 原文地址:https://www.cnblogs.com/pnljs/p/2933672.html
Copyright © 2011-2022 走看看