如何将DataTable转换为数组?
将我的转换器从DataTable导出到object [,]
uint rows = (uint)table.Rows.Count;
uint columns = (uint)table.Columns.Count;
var data = new object[rows, columns];
int i = 0;
foreach (System.Data.DataRowView drv in table.DefaultView)
{
System.Data.DataRow ViewRow = drv.Row;
data[i] = drv.Row.ItemArray.Clone() as object[];// Wrong number of indices inside []; expected 2
i++;
}
答案 0 :(得分:2)
uint rows = (uint)table.Rows.Count;
uint columns = (uint)table.Columns.Count;
var data = new object[rows, columns];
int i = 0;
foreach (System.Data.DataRowView drv in table.DefaultView)
{
for( int x = 0; x<columns; x++)
{
System.Data.DataRow ViewRow = drv.Row;
data[i, x] = drv[x];
i++;
}
}