DataTable To List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

DataTable To List

Demo Code


using System.Reflection;
using System.Data;
using System.ComponentModel;
using System.Collections.Generic;
using System;/*  ww  w .  ja  v a  2 s  .  c o  m*/

public class Main{
        public static IList<T> ToList<T>(this DataTable table)
        {
            if (table == null) return null;

            var rows = new List<DataRow>();

            foreach (DataRow row in table.Rows)
            {
                rows.Add(row);
            }

            return ToDataTable<T>(rows);
        }
}

Related Tutorials