none
convert Linq Result to datatable RRS feed

  • Question

  • how i can convert following query result to dataTable

     var query = (from x in dtn.AsEnumerable()
                                     join y in DTFacilityTax.AsEnumerable() on x.Field<dynamic>("FacilityId") equals y.Field<dynamic>("FacilityId")
    
    
                                     select new { FacilityId = x.Field<dynamic>("FacilityId"), FacilityVAT = y.Field<dynamic>("FacilityVAT"), FacilityServiceTax = y.Field<dynamic>("FacilityServiceTax") }).ToList();
    

    Thursday, November 27, 2014 11:58 AM

Answers

  • Hello Vithal,

    From your provided LINQ query syntax, it seems to be a LINQ2DataSet rather than LINQ2SQL, is it right?

    If it is the LINQ2DataSet, you could use the DataTableExtensions.CopyToDataTable Method to convert the LINQ query result to a DataTable directly.

    If it is the LINQ2SQL, unfortunately, there is not a method like the CopyToDataTable above which could do it automatically. You could check this link which provides an extend method.

    sRegards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 2:36 AM
    Moderator