How to create a testing / temp in memory only DataTable using Linq

Rahul Chowdhury

Is there any way to create a datatable with static value let say

Column : col1,col2.....coln
Rows : for n number of rows 

For first row values row11,row12......row1n
for second row values row21,row22.....row2n
.
.
.
for nth row values rown1,rown2......rownn

Any stylish way to do it using lambda/linq...may be in a single line in a expertise way ..

Hogan

I know it is an un-cool question ("outdated technology" - John Saunders) but I can't resist:

const int cols = 6;
const int rows = 20;

DataTable nt = new DataTable("new table");

nt.Columns
  .AddRange(
     Enumerable
      .Range(1,cols)
      .Select(x => new DataColumn("col"+x.ToString())).ToArray());

Enumerable
 .Range(1,rows).ToList()
 .ForEach(x => nt.Rows
                 .Add(
                  Enumerable
                  .Range(1,cols)
                  .Select(y => "row"+x.ToString()+"col"+y.ToString()).ToArray()));

Sorry about the strange formatting but I did not want a horizontal scroll bar.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to get data to datatable using linq

From Dev

Datatable LINQ select datarow only returning one row and how to order

From Dev

MySql: how to create temp table by using dynamic select statement?

From Dev

How to create Excel sheet using DataTable and the ExcelLibrary?

From Dev

How to select * from DataTable Where... using Linq

From Dev

How to sum between dates in a DataTable with multi conditions using LINQ?

From Dev

How to group DataTable results using Linq query expression

From Dev

how to groupby on only one column using linq

From Dev

how to group by one column only using linq?

From Dev

how to groupby on only one column using linq

From Dev

how to group by one column only using linq?

From Dev

LIKE query on DataTable using LINQ

From Dev

Search datatable using Linq to dataset

From Dev

Using Linq to GroupBy and Sum datatable

From Dev

Using LINQ and Storing Results in a DataTable

From Dev

Group by on datatable by using linq query

From Dev

LINQ To Datatable using "Any" with a List

From Dev

Loop datatable using linq expression

From Dev

How do create a join by using linq?

From Dev

How I can filter a dataTable with Linq to datatable?

From Dev

How to Sort only the current page using Jquery Datatable

From Dev

Is it possible to create and run a bigquery temp table locally in memory?

From Dev

How to Group By on Columns in datatable in Linq

From Dev

How to create DataTable using jQuery in UI of MVC4?

From Dev

How to create a datatable in xsd file using c#

From Dev

How to create and read from the same temp SQL table using node js

From Dev

Create in-memory only gzip

From Dev

How to create/setup vpn using only SSH?

From Dev

How to create rating system using only css

Related Related

  1. 1

    how to get data to datatable using linq

  2. 2

    Datatable LINQ select datarow only returning one row and how to order

  3. 3

    MySql: how to create temp table by using dynamic select statement?

  4. 4

    How to create Excel sheet using DataTable and the ExcelLibrary?

  5. 5

    How to select * from DataTable Where... using Linq

  6. 6

    How to sum between dates in a DataTable with multi conditions using LINQ?

  7. 7

    How to group DataTable results using Linq query expression

  8. 8

    how to groupby on only one column using linq

  9. 9

    how to group by one column only using linq?

  10. 10

    how to groupby on only one column using linq

  11. 11

    how to group by one column only using linq?

  12. 12

    LIKE query on DataTable using LINQ

  13. 13

    Search datatable using Linq to dataset

  14. 14

    Using Linq to GroupBy and Sum datatable

  15. 15

    Using LINQ and Storing Results in a DataTable

  16. 16

    Group by on datatable by using linq query

  17. 17

    LINQ To Datatable using "Any" with a List

  18. 18

    Loop datatable using linq expression

  19. 19

    How do create a join by using linq?

  20. 20

    How I can filter a dataTable with Linq to datatable?

  21. 21

    How to Sort only the current page using Jquery Datatable

  22. 22

    Is it possible to create and run a bigquery temp table locally in memory?

  23. 23

    How to Group By on Columns in datatable in Linq

  24. 24

    How to create DataTable using jQuery in UI of MVC4?

  25. 25

    How to create a datatable in xsd file using c#

  26. 26

    How to create and read from the same temp SQL table using node js

  27. 27

    Create in-memory only gzip

  28. 28

    How to create/setup vpn using only SSH?

  29. 29

    How to create rating system using only css

HotTag

Archive