更新时间:2022-12-12 09:22:57
Refer
http:// ***。 com / questions / 17107220 / convert-dataset-to-object-list [ ^ ]
k。实际上我正在尝试编写动态函数,我会将数据集传递给该功能最终我希望结果列表,每次ds都有不同的数据,如表计数和类型
喜欢
public List dstolist(ds Dataset)
{
_objects = new List();
'
'
'
返回_objects;
}
尝试这样做的麻烦就是你做不到返回任何特别聪明的东西:你不能假设单独的表之间有任何互连,所以你最终只是将每个表数据附加在前一个底部的底部。
这可能会有所帮助:使用Generic将数据表转换为集合 [ ^ ] 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://***.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>