Q:

Linq query is not executing properly

I'am trying to sum up DataTable column's in linq. But when the program is running the foreach loop is not executing. I already checked milion times if the column names are equal to datatable.
resultDataTable.Columns.Add("User ID");
resultDataTable.Columns.Add("Amount");
resultDataTable.Columns.Add("Order number");

var query = from row in result.AsEnumerable()
            group row by row.Field<string>("User ID") into grp                
            select new
            {
                Id = grp.Key,
                Sum = grp.Sum(r => r.Field<int>("Amount")),
                Sum2 = grp.Sum(r => r.Field<int>("Order number"))       
            };

foreach(var item in query)
{
    resultDataTable.Rows.Add(item.Id, item.Sum, item.Sum2);
}

The result is DataTable with 3 columns. The first one is name and last name, second one is number and third is number also.
Any ideas why this doesn't work?

A:

I assume that you have created the source table in the same way as the destination table, by adding the columns manually. Then i guess that they also contained String-columns instead of int columns. Note that the default is String.
So following creates and adds three columns of type string:
resultDataTable.Columns.Add("User ID");
resultDataTable.Columns.Add("Amount");
resultDataTable.Columns.Add("Order number");

Instead use the overload:
resultDataTable.Columns.Add("User ID");
resultDataTable.Columns.Add("Amount", typeof(int));
resultDataTable.Columns.Add("Order number", typeof(int));

Why is that important? Because you otherwise can't use Sum = grp.Sum(r => r.Field<int>("Amount")) since that column's type isn't int but string and you'll get a runtime InvalidCastException in Field at the foreach. Maybe you have an empty try...catch somewhere which swallows this exception and should be avoided.
A better way to create the table and the columns, if the destination table has the same columns is to use DataTable.Clone:
DataTable resultDataTable = result.Clone(); // same columns but empty

