Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var recordsV2 = NgDb.UCB_Cimplicity_EReferral_GetFulfillmentsV2(companyID, clientID, programID, supplierName).ToList();


how to convert the above var recordsV2 to datatable.


thanks in advance.
Posted
Comments
Arasappan 27-Nov-15 5:39am    
did u get the values in recordsV2

C#
IEnumerable<datarow> query = NgDb.UCB_Cimplicity_EReferral_GetFulfillmentsV2(companyID, clientID, programID, supplierName);
// Create a table from the query.
DataTable boundTable = query.CopyToDataTable<datarow>();

Or can use a customized method using reflection to convert LINQ result to datatable
C#
public DataTable LINQResultToDataTable<t>(IEnumerable<t> Linqlist)  
       {  
           DataTable dt = new DataTable();           
           PropertyInfo[] columns = null;  
           if (Linqlist == null) return dt;  
           foreach (T Record in Linqlist)  
           {                 
               if (columns == null)  
               {  
                   columns = ((Type)Record.GetType()).GetProperties();  
                   foreach (PropertyInfo GetProperty in columns)  
                   {  
                       Type colType = GetProperty.PropertyType;  
                       if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()  
                       == typeof(Nullable<>)))  
                       {  
                           colType = colType.GetGenericArguments()[0];  
                       }  
                       dt.Columns.Add(new DataColumn(GetProperty.Name, colType));  
                   }  
               } 
               DataRow dr = dt.NewRow();  
               foreach (PropertyInfo pinfo in columns)  
               {  
                   dr[pinfo.Name] = pinfo.GetValue(Record, null) == null ? DBNull.Value : pinfo.GetValue(Record, null);  
               }  
               dt.Rows.Add(dr);  
           }  
           return dt;  
       } 
 
Share this answer
 
v3
Hello ,
Check this link : Convert LINQ Query Result to Datatable

Thanks
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900