I want to convert a DataRow
array into DataTable
... What is the simplest way to do this?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
For .Net Framework 3.5+
But if there is no rows in the array, it can cause the errors such as The source contains no DataRows. Therefore, if you decide to use this method
CopyToDataTable()
, you should check the array to know it has datarows or not.Reference available at MSDN: DataTableExtensions.CopyToDataTable Method (IEnumerable)
Another way is to use a DataView
Why not iterate through your DataRow array and add (using DataRow.ImportRow, if necessary, to get a copy of the DataRow), something like:
Make sure your dataTable has the same schema as the DataRows in your DataRow array.
Simple way is: