有关的数据表 [英] Data table regarding

查看:76
本文介绍了有关的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp .net中将列中的所有行存储在数组中而没有任何循环c#

how to store a column all rows in a array without any loop in asp .net c#

推荐答案

如果要求是从DataTable 所有行的对应于特定Column 的值,而无需使用循环,则LINQ 查询可按如下方式使用:
If the requirement is to populate an array from the values of all rows of a DataTable corresponding to a particular Column without using a loop, then LINQ query can be used as follows:
DataTable dataTable1 = new DataTable("DataTable1");
dataTable1.Columns.Add("Month", typeof(string),null);
dataTable1.Columns.Add("Name", typeof(string),null);
dataTable1.Columns.Add("Amout", typeof(int),null);

dataTable1.Rows.Add("March","John",0);
dataTable1.Rows.Add("April","Ishan",25);
dataTable1.Rows.Add("May","Raman",50);
dataTable1.Rows.Add("March","Sheron",0);
dataTable1.Rows.Add("March","Ramesh",75);

string[] names = dataTable1.AsEnumerable().Select (t => t.Field<string>("Name")).ToArray();

//Contents of names
//John 
//Ishan 
//Raman 
//Sheron 
//Ramesh</string>


这篇关于有关的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆