Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to Convert data set with multiple Tables(i.e ds.tables.count>1) to List...Plz Any Help
Posted
Comments
OriginalGriff 28-Jan-14 5:54am    
What have you tried?
Where are you stuck?
Tharun@Chinna 28-Jan-14 6:08am    
Hi,
Actually I tried with Data set With Single Table i.e .Tables(0). But What i'm Trying is my data set have 4 tables. i want to convert 4 tables data into single list..
OriginalGriff 28-Jan-14 6:11am    
Do all the tables contain the same number and type of columns?
Tharun@Chinna 28-Jan-14 6:17am    
No, All Tables Have Different Column names,type & Column.count Also Different.
OriginalGriff 28-Jan-14 6:28am    
So how do you expect a single List to cope with them all? :laugh:
One way is to have a List of Lists, and allow a separate list for each table in the set - but that kind of defeats the purpose, I'm guessing!

So if they are all different, how do you propose to use the end result? Unless there is some way to tie the different tables together, it's going to be hard to work with.

 
Share this answer
 
Comments
Tharun@Chinna 28-Jan-14 6:28am    
Hi,
Actually I tried with Data set With Single Table i.e .Tables(0). But What i'm Trying is my data set have 4 tables. i want to convert 4 tables data into single list.
All Tables Have Different Column names,type & Column.count Also Different.
JoCodes 28-Jan-14 6:56am    
In that case you need to have List<object> type so any type can be added.
"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!
 
Share this answer
 
XML
ds.fill(dt);
List&lt;DataRow&gt; list = new List&lt;DataRow&gt;();
foreach(Datarow row in dt.rows)
{
 list.add((DataRow)row);
}</datarow></datarow>
 
Share this answer
 
v2
Comments
Tharun@Chinna 28-Jan-14 6:27am    
Hi,
Actually I tried with Data set With Single Table i.e .Tables(0). But What i'm Trying is my data set have 4 tables. i want to convert 4 tables data into single list.
All Tables Have Different Column names,type & Column.count Also Different.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900