Convert DataTable to LINQ: Unable to query multiple fields?

It sounds like you're writing a bad select statement. Try the following: public void Something(DataTable dt) { var data = from row in dt.AsEnumerable() select new { Order = row"Order".ToString(), Something = row"Something".ToString(), Customer = row"Customer".ToString(), Address = row"Address".ToString() }; } That will create a new collection of Anonymously Typed objects that you can iterate over and use as needed. Keep in mind, though, that you want be able to return data from the function.

If you need that functionality, you need to create a concrete type to use (in place of anonymous types).

Yeah I was forgetting the new keywords. Still not used to these anonymous delegates and all that, I forgot. Thanks!

– Mohgeroth Jul 27 '10 at 13:21.

I think you should use select new like this query for example: var q = from o in db. Orders where o.Products.ProductName. StartsWith("Asset") && o.

PaymentApproved == true select new { name = o.Contacts. FirstName + " " + o.Contacts. LastName, product = o.Products.

ProductName, version = o.Products. Version + (o.Products. SubVersion * 0.1) }.

You probably want the following. Var data = from row in dt.AsEnumerable() select new { Order = row"Order".ToString(), Version = row"Version".ToString() }.

Importing a spreadsheet I have filled a DataTable object with that data and returns expected results. Works as expected giving me a list of orders. However I cannot add other fields to this EnumerableRowCollection.

I'm thinking I need to alias the column name but I'm having no luck. What am I missing here?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions