C # Convert 2D array to dataset / datatable

Does anyone know how to turn a 2D array into a dataset or datatable in C #?

Source: range of values ​​from excel (interop) in array object [,].

Thank.

+2


source to share


3 answers


Please take a look at the following article



Convert Excel Table to DataSet, DataTable and Multidimensional Array

+3


source


You can create dataset / datatable in code: http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx



From there, you will loop through the array and fill the rows and their columns with information about the array.

+1


source


The option given by mr.phoenix should work. If you are stuck with working 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);
}

      

+1


source







All Articles