views:

2163

answers:

3

hi, 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.

+1  A: 

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.

klabranche
+2  A: 

Please take a look at the following article

Converting an Excel Spreadsheet to a DataSet, DataTable and Multi-Dimensional Array

rahul
+1  A: 

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);
}
Perpetualcoder