如何將DataTable轉換爲Array?將DataTable轉換爲對象[,]
來源從數據表我轉換爲對象[,]
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++;
}
你可能想嘗試指定克隆陣列'...爲對象的大小[dr.Row.ItemArray.Length ] //或類似這樣的東西,或者每個項目克隆它的項目。 – ckruczek