Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alias fields from a DataTable in LINQ?

Tags:

c#

linq

datatable

How can I give an alias name to fields selected from a DataTable using LINQ?

like image 779
Kishore Kumar Avatar asked Aug 18 '10 04:08

Kishore Kumar


2 Answers

var output = dataTable.Rows.Cast<DataRow>().Select(r => new 
    {
       alias1 = r["Column1"].ToString(),
       alias2 = r["Column2"].ToString(),
       alias3 = r["Column3"].ToString(),
       /// etc...
    });
like image 154
Kelsey Avatar answered Nov 02 '22 15:11

Kelsey


var query =dataTable.Rows.Cast<DataRow>().Select(row => new 
{
   aliasName1 = row["Column1"].ToString(),
  aliasName2 = row["Column2"].ToString()
 });
like image 1
anishMarokey Avatar answered Nov 02 '22 17:11

anishMarokey