本文介绍了将数据表转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static IList<Task> GetAllTasks()
{
return _taskSet.Task.ToList<Task>();
// return sampleData.ToList();
}
我正在将dataTable转换为列表,但出现以下错误。我如何将表转换为列表。
I am converting a dataTable to list and I getting the following error. how can i convert a table to List.
Error 1 Instance argument: cannot convert from orkTimeTable.Dataset.TaskSet.TaskDataTable' to 'System.Collections.Generic.IEnumerable<WorkTimeTable.Model.Task>' c:\users\huzaifa.gain\documents\visual studio 2010\Projects\WorkTimeTable\WorkTimeTable\Model\TaskDataService.cs 24 20 WorkTimeTable
Error 2 'WorkTimeTable.Dataset.TaskSet.TaskDataTable' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments c:\users\huzaifa.gain\documents\visual studio 2010\Projects\WorkTimeTable\WorkTimeTable\Model\TaskDataService.cs 24 20 WorkTimeTable
推荐答案
public static IList<Task> GetAllTasks()
{
List<Task> taskList = new List<Task>();
foreach (TaskSet.TaskRow r in _taskSet.Task.AsEnumerable())
taskList.Add(new WorkTimeTable.Model.Task()
{
Name = r.Name, Description = r.Description, ToDateTime = r.ToDate, FromDateTime = r.FromDate, TotalTime = r.TimeSpan
});
return taskList;
}
这篇关于将数据表转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!