how Would i get data in a new array from dataset i have four column in dataset but want to put only "power" and "date" co开发者_StackOverflow中文版lumn data in array ?
Hopes for your suggestions..
Regards,
You could define a custom class which will represent your data:
public class Item
{
public int Power { get; set; }
public DateTime Date { get; set; }
}
and then you could use a LINQ query on your DataSet to extract the necessary information:
DataSet dataSet = ...
Item[] result = dataSet
.Tables[0]
.Rows
.Cast<DataRow>()
.Select(row => new Item
{
Power = row.Field<int>("power"),
Date = row.Field<DateTime>("date"),
})
.ToArray();
Depending on your .NET version and final usage you could use LINQ to DataSet to pull it out and project to a new type.
Something like this would work, if working on a Typed Dataset
var limitedData = from x in myDataSet
select new { Power = x.power, MyDate = x.date };
Then you have an IEnumerable that you can work with, you could use .ToArray()
if you really need it in an array.
精彩评论