Click here to Skip to main content
14,241,575 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone! Can any one help me in converting the List into DataTable?I did like this



DataTable dt1 =(DataTable) DataDecl.CMInfo.ToList();
DataSet ds = new System.Data.DataSet();
ds.Tables.Add(DataDecl.CMInfo.ToList());

Is this the right way?
Posted
Comments
Hiren solanki 24-Sep-10 5:50am
   
you can answer accepted and vote, if it helped .
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
hemantwithu 24-Sep-10 5:49am
   
Thanks.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Try this..

public static DataTable ListToDataTable(List<T> mylist)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("myCol", mylist[0].IntField.GetType());
    foreach (MyRecord rc in mylist)
    {
        dt.Rows.Add(rc.myCol);
    }
    return dt;
}
   
Comments
hemantwithu 24-Sep-10 7:37am
   
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100