NewsFeed   -
KỸ THUẬT LẬP TRÌNH
S  M  L
How to Convert a LINQ result to DATATABLE? - C#
var rows = [ORIGINAL DATA TABLE].Select("id>5");

var dtb=[ORIGINAL DATA TABLE].Clone();

foreach(DataRow r in rows)
{
    var newRow = dtb.NewRow();
    newRow.ItemArray = r.ItemArray;
    dtb.Rows.Add(newRow);//I'm doubtful if you need to call this or not
}

-------------------------------------

public static DataTable ToADOTable(this IEnumerable varlist)
    {
        DataTable dtReturn = new DataTable();
        // Use reflection to get property names, to create table
        // column names
        PropertyInfo[] oProps = typeof(T).GetProperties();
        foreach (PropertyInfo pi in oProps)
        {
            Type colType = pi.PropertyType;
            if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                colType = colType.GetGenericArguments()[0];
            dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
        }
        foreach (T rec in varlist)
        {
            DataRow dr = dtReturn.NewRow();
            foreach (PropertyInfo pi in oProps)
                dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
            dtReturn.Rows.Add(dr);
        }

        return (dtReturn);
    }
- 04/15/2011
Search:
NGHỆ THUẬT - PHIM - ẢNH

HÌNH ẢNH ĐẸP

Photo

Album: CinemaGraphs
< August 2011 >
Sun Mon Tue Wed Thu Fri Sat
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
4 5 6 7 8 9 10
More... (All Collections)
H2O NEWS

Everything Meaning To You!

Email: [email protected]

Website: emty.org

Liên hệ

Đặt làm trang chủ

@