I was just wondering is there a faster or more efficient method to convert a DataTable to an object?

The method I am currently using is this:

public class Job {
    int JobID { get; set; }
    decimal JobCost { get; set; }

    Job(DataRow dr)
        ID = Convert.ToInt32(dr["ID"]);
        if(dr["JobCost "] != DBNull.Value)
            JobCost = Convert.ToDecimal(dr["DelAmt"]);

public static List<Job> FillObjects()
    DataTable dtJobs = JobController.GetJobTable();

    foreach (DataRow dr in dtJobs.Rows)
        jobs.Add(new Job(dr));          

    return jobs

This is an obviously simplified example, however this gets rather slow with many rows in the data table and many properties in the object. Is there a faster or more efficient method for doing something like this?

Thanks in advance for any replies!

Related posts

Recent Viewed