Reputation: 11356
does anyone know how to turn a 2-dimensional array into a dataset or datatable in c#?
Source: a range of values from excel (interop) in an object[,] array.
Thanks.
Upvotes: 2
Views: 16224
Reputation: 13571
Option given by mr.phoenix should work. If you are stuck with dealing with arrays...here is some pseudocode.
var sample = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};
var table = new DataTable("SampleTable");
// iteration logic/loops for the array
{
var newRow = table.NewRow();
newRow["Col1"] = sample[i,j0]; // like sample [0,0]
newRow["Col2"] = sample[i,j1]; // like sample [0,1]
table.Add(newRow);
}
Upvotes: 1
Reputation: 187080
Please take a look at the following article
Converting an Excel Spreadsheet to a DataSet, DataTable and Multi-Dimensional Array
Upvotes: 3
Reputation: 21088
You can create a dataset / datatable in code: http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx
From there you would loop through your array and populate the rows and their columns with the array information.
Upvotes: 1