>So is there a reason you didn't create a new table an manually loop through the rows? You are trying to force LINQ to do something it wasn't designed to do (create a new DataTable with a different structure). If you need the results as a DataTable, it needs to have a structure defined so that DataRows can be created for it. If you don't want to do that, you could write a method that would convert an IEnumberable< object> to a DataTable. Or you could create a class to hold the results of your query and use that instead of a DataTable to pass the results to the other function.
I thought I can use LINQ to do this transformation in memory without a need to loop through the rows. But looks like I would need to do it manually as suggested by Bill originally.
Unless I will try to incorporate most of the code from our conversion methods here.
The only reason I need a datatable is because our method to convert to our XML string accepts datatable. Since it loops through every row, it means I would need double looping. I'd rather try to figure out if I can somehow create something similar to use and do that loop directly myself.
If it's not broken, fix it until it is.
My Blog