The given below example I have one userdetails class have properties of user information and another one is data set to list conversion method. If you pass dataset to the function then the function will return collection of userdetails list.
Sample Code:
Convert DataSet to List Function:
public IList
{
List
try
{
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
var myData = ds.Tables[0].AsEnumerable().Select(r => new UserDetails
{
UserID = r.Field
UserName = r.Field
EmailID = r.Field
Name = r.Field
RoleID = r.Field
Sex = r.Field
DOB = r.Field
Mobile = r.Field
IsActive = r.Field
});
lst = myData.ToList();
}
}
catch (Exception ex)
{
Comman.ErrorLog(ex.Message);
}
return lst;
}
public class UserDetails
{
public string UserID { get; set; }
public string UserName { get; set; }
public string EmailID { get; set; }
public string Name { get; set; }
public string RoleID { get; set; }
public string Sex { get; set; }
public DateTime? DOB { get; set; }
public string Mobile { get; set; }
public bool IsActive { get; set; }
}
1 comment:
Post a Comment