如何将数据集转换为列表 [英] How To Convert Dataset To List
本文介绍了如何将数据集转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将包含多个表的数据集(即ds.tables.count> 1)转换为List ... Plz任何帮助
解决方案
Refer
http:// stackoverflow。 com / questions / 17107220 / convert-dataset-to-object-list [ ^ ]
k。实际上我正在尝试编写动态函数,我会将数据集传递给该功能最终我希望结果列表,每次ds都有不同的数据,如表计数和类型
喜欢
public List dstolist(ds Dataset)
{
_objects = new List();
'
'
'
返回_objects;
}
尝试这样做的麻烦就是你做不到返回任何特别聪明的东西:你不能假设单独的表之间有任何互连,所以你最终只是将每个表数据附加在前一个底部的底部。
这可能会有所帮助:使用Generic将数据表转换为集合 [< a href =http://www.codeproject.com/Tips/195889/Convert-Datatable-to-Collection-using-Generictarget =_ blanktitle =New Window> ^ ] br />
如果您遵循其工作原理,您应该能够为多个表生成通用解决方案。
我不禁想到它在实践中没有多大用处!
ds.fill(dt) ;
List& lt; DataRow& gt; list = new List& lt; DataRow& gt;();
foreach(在dt.rows中的Datarow行)
{
list.add((DataRow)row);
} < / datarow > < / datarow >
I'm trying to Convert data set with multiple Tables(i.e ds.tables.count>1) to List...Plz Any Help
解决方案
Refer
http://stackoverflow.com/questions/17107220/convert-dataset-to-object-list[^]
"k. Actually I'm Trying to write a Dynamic function, I'll pass data set to that function by end i want result in List,In every time ds have different data, like table count & type
like
public List dstolist(ds Dataset)
{
_objects = new List();
'
'
'
return _objects;
}"
The trouble with trying to do that is that you can't return anything particularly intelligent: You can't assume any interconnection between the separate tables, so you end up just "attaching" each table data on the bottom of the previous one.
This may help: Convert Datatable to Collection using Generic[^]
If you follow how that works, you should be able to generate a "generic" solution for multiple tables.
I can't help thinking it's not going to be much use in practice though!
ds.fill(dt); List<DataRow> list = new List<DataRow>(); foreach(Datarow row in dt.rows) { list.add((DataRow)row); }</datarow></datarow>
这篇关于如何将数据集转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文