/*
* 将一个二维数组转换城datatable。
*/
public static DataTable ConvertToDataTable(string[,] arr)
{
DataTable dataSouce = new DataTable();
for (int i = 0; i < arr.GetLength(1); i++)
{
DataColumn newColumn = new DataColumn(i.ToString(), arr[0, 0].GetType());
dataSouce.Columns.Add(newColumn);
}
for (int i = 0; i < arr.GetLength(0); i++)
{
DataRow newRow = dataSouce.NewRow();
for (int j = 0; j < arr.GetLength(1); j++)
{
newRow[j.ToString()] = arr[i, j];
}
dataSouce.Rows.Add(newRow); // .ItemArray
}
return dataSouce;
}
将一个二维数组转换城datatable。
最新推荐文章于 2023-03-17 23:36:44 发布