I have a DataSet
and I want to convert the DataSet
into List
T - type object
How convert my DataSet
?
First of all, you're on the right track, but you should be thinking in terms of IEnumerable
rather than List
. And here is how you would do that:
var myData = ds.Tables[0].AsEnumerable()
.Select(r => new {column1 = r[0].ToString(),
column2 = r[1].ToString()
/*etc*/
});
Never convert an IEnumerable to a List before you absolutely need to.