关于网友提出的“ 如何选择datatable中的列”问题疑问,本网通过在网上对“ 如何选择datatable中的列”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 如何选择datatable中的列
描述: 如何对一个datatable进行sql server中的一些语法
如select 列a,列b from 表 where 列a=''.
要是没办法 ,或者说把datatable转成list,然后再用linq实现我想选择datatable中某些列的功能。
给个例子,谢谢
解决方案1: http://tech.it168.com/KnowledgeBase/Articles/9/0/1/901f89bcfff296a73c7c4f91117cc177.htm
这个看对你有帮助不
解决方案2: dataTable.Rows[randomSelector.Next(dataTable.Rows.Count)];
LINQ TO DATAset操作
public IList GetList (DataTable table)
{
IList list = new List ();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance ();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
pro.SetValue(t, value, null);
}
}
list.Add(t);
}
return list;
}
tb.OfType().Select(row=>
new YourType{Field1=(string)row["field1"],Field2=(int)row["field2"]}).ToList();
解决方案3:
还是要转成数组 然后再来查找比较好
是你要的不
以上介绍了“ 如何选择datatable中的列”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1945223.html