Answers for "datatable to array c#"

C#
0

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;
}
Posted by: Guest on July-27-2021
0

datatable to array c#

string[] arrray = dt.Rows.OfType<DataRow>().Select(k => k[0].ToString()).ToArray();
Posted by: Guest on October-22-2021

C# Answers by Framework

Browse Popular Code Answers by Language