Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

array object to datatable c#

public static DataTable ArraytoDatatable(Object[,] numbers)
{                 
    DataTable dt = new DataTable();
    for (int i = 0; i < numbers.GetLength(1); i++)
    {
        dt.Columns.Add("Column" + (i + 1));
    }

    for (var i = 0; i < numbers.GetLength(0); ++i)
    {
        DataRow row = dt.NewRow();
        for (var j = 0; j < numbers.GetLength(1); ++j)
        {
            row[j] = numbers[i, j];
        }
        dt.Rows.Add(row);
    }
    return dt;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #array #object #datatable
ADD COMMENT
Topic
Name
6+8 =