Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill DataTable with Array

I've an array like this one:

    const int dim = 1000;
    double[,] array = new double[dim, dim];

    Random ran = new Random();
    for (int r = 0; r < dim; r++)
        for (int c = 0; c < dim; c++)
            array[r, c] = (ran.Next(dim));

    DataTable dataTable = new DataTable();

Can I fill the dataTable with the array data?

like image 547
Jaime Oro Avatar asked Mar 19 '11 15:03

Jaime Oro


People also ask

How do I extract data from an array in DataTables?

Approach: The DataTables plugin’s column.data option is used to extract data from arrays using the dot notation. The dot (.) is used for accessing arrays or subarrays of the column.data option.

Do DataTables need to be on the page?

A table must be available on the page for DataTables to use. This examples shows an empty table element being initialising as a DataTable with a set of data from a Javascript array. The columns in the table are dynamically created based on the columns.title configuration option.

Can I create a table from dynamic information passed to DataTables?

At times you will wish to be able to create a table from dynamic information passed directly to DataTables, rather than having it read from the document.

Can I use list of (list of (string) ) in a add data row activity?

List of (DataRow). Sure. I mean use the List of (List of (String)) in a Add Data Row activity ? Use the internal List (Of String) as a row input I mean ? Because in the Add Data Row activity, the input has to be either an Array or a DataRow. If I use DataRow I can’t fill it in a random order in the previous step…


2 Answers

Try something like this:

var dt = new DataTable();
//AddColumns
for (int c = 0; c < dim; c++)
    dt.Columns.Add(c.ToString(), typeof(double));
//LoadData
for (int r = 0; r < dim; r++)
    dt.LoadDataRow(arry[r]);
like image 196
gor Avatar answered Oct 07 '22 12:10

gor


You have to set up the Columns and then load one row at a time using

DataTable.LoadDataRow() which takes object[]

Check out the example in MSDN page.

like image 33
Bala R Avatar answered Oct 07 '22 13:10

Bala R