Converting DataSet object to List using Linq

vishalneeraj-24503
Posted by vishalneeraj-24503 under LINQ category on | Points: 40 | Views : 659
Suppose,we have EmployeeDetails class as shown below:-
public class EmployeeDetails
{
public int Employee_Id{ get; set; }
public string Employee_Name { get; set; }
public string Address{ get; set; }
}

//Now DataSet part:-I am assuming that,DataSet is filled with Employee Data
public List Get_Employee_Information(int Emp_Id)
{
DataSet ds = new DataSet();
List obj_emp = new List();
try
{
obj_emp = ds.Tables[0].AsEnumerable().Select(data => new EmployeeDetails() { Employee_Id = (int)data["Employee_Id"], Employee_Name = (string)data["Employee_Name"], Address = (string)data["Address"]}).ToList();
return obj_emp;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (ds != null)
{
ds.Dispose();
}
}
}

Comments or Responses

Login to post response