Convert generic List/Enumerable to DataTable?

后端 未结 27 2224
臣服心动
臣服心动 2020-11-21 23:20

I have few methods that returns different Generic Lists.

Exists in .net any class static method or whatever to convert any list into a datatable? The only thing tha

27条回答
  •  忘掉有多难
    2020-11-21 23:53

    To Convert Generic list into DataTable

    using Newtonsoft.Json;

    public DataTable GenericToDataTable(IList list)
    {
        var json = JsonConvert.SerializeObject(list);
        DataTable dt = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));
        return dt;
    }
    

提交回复
热议问题