datatable 转 数组 问题
datatable有n行6列,假设如下111213141516212223242526313233343536414243444546如何转成如下数组?{{11,12,1...
datatable 有n行6列,假设如下
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
如何转成如下数组?
{ {11,12,13,14,15,16},{21,22,23,24,25,26},{31,32,33,34,35,36},{41,42,43,44,45,46} } 展开
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
如何转成如下数组?
{ {11,12,13,14,15,16},{21,22,23,24,25,26},{31,32,33,34,35,36},{41,42,43,44,45,46} } 展开
2个回答
展开全部
DataTable datatable = new DataTable();
int row = datatable.Rows.Count;
int col = datatable.Columns.Count;
int[][] ary = new int[row][];
for (int i = 0; i < row; i++)
{
ary[i] = new int[col];
for (int j = 0; j < col; j++)
{
ary[i][j] = System.Convert.ToInt32(datatable.Rows[i][j]);
}
}
两个for循环解决。
int row = datatable.Rows.Count;
int col = datatable.Columns.Count;
int[][] ary = new int[row][];
for (int i = 0; i < row; i++)
{
ary[i] = new int[col];
for (int j = 0; j < col; j++)
{
ary[i][j] = System.Convert.ToInt32(datatable.Rows[i][j]);
}
}
两个for循环解决。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询