LINQ query on a DataTable

前端 未结 23 1432
执笔经年
执笔经年 2020-11-22 01:59

I\'m trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example:

23条回答
  •  后悔当初
    2020-11-22 02:28

    var query = from p in dt.AsEnumerable()
                        where p.Field("code") == this.txtCat.Text
                        select new
                        {
                            name = p.Field("name"),
                            age= p.Field("age")                         
                        };
    

    the name and age fields are now part of the query object and can be accessed like so: Console.WriteLine(query.name);

提交回复
热议问题