I'm trying to select a number DataRows with only specified fields from a Linq query, and then use these DataRows to populate a DataTable. The problem is that when I add these DataRows to the new DataTable I'm expect both ID and Name field to be populated respectively. However, the ID field in the DataTable contains both ID and Name values. Can someone point out what I'm doing wrong.
Here's the code:
var query2 = from s in Tables[Table_Sec].AsEnumerable()
where query.Contains(s["sectype"])
select new { id = s["id"], name = s["name"] }; // I only want these fields
DataTable dt = new DataTable(); // Create my new dataTable
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("name", typeof(string));
foreach(var row in query2)
{
dt.Rows.Add(row); // ID field contains both ID and Name strings. Name field contains nothing
}