如何进行这个类型转换(LINQ查询弱类型dataset)

helloxxxxx111 2010-07-30 07:53:19

public static void QuaryClassList(out List<string> AllClassList)
{
DataTable myDataTable = OriginalDS.Tables[0];
var ClassQuary =
from tempRow in myDataTable.AsEnumerable()
select tempRow.Field<string>("班级").Distinct();

AllClassList = ClassQuary.ToList(); //这段代码会出问题,因为无法进行类型转换
}


OK,我查询一个弱类型的DATASET,获得一个System.Collections.Generic.List<System.Collections.Generic.IEnumerable<char>>的查询结果。
我想要得到List<string>,也就是System.Collections.Generic.List<string>;

如果我直接在Distinct()后面加cast<string>(),会将结果转换为System.Collections.Generic.List<System.Collections.Generic.IEnumerable<string>>

尴尬。。。
请问如何解决这个问题,或者说用其他方法得到弱类型DS某一列的内容,且返回类型为list<string>??

抱歉分数不够了-。-经常潜水,谢谢大家
...全文
245 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sunpire 2010-07-30
  • 打赏
  • 举报
回复

AllClassList = ClassQuary.ToList();
改为
AllClassList = new List<string>( ClassQuary );
wuyq11 2010-07-30
  • 打赏
  • 举报
回复
DataTable products = ds.Tables["Product"];
IEnumerable<DataRow> productList = products.AsEnumerable().ToList();
IEnumerable<DataRow> query =
from product in productList
orderby product.Field<string>("Name")
select product;
http://stackoverflow.com/questions/2281743/convert-datatable-to-listt
helloxxxxx111 2010-07-30
  • 打赏
  • 举报
回复
ok-.-已自己解决,在distinct 后面加as string-.-

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧