二维数组转换成DataTable

来源:互联网 发布:网络文案是什么 编辑:程序博客网 时间:2024/05/17 13:10
        public static DataTable ToDataTable(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);                     }                  return dataSouce;          } 





原创粉丝点击