troubleshooting Question

How to display selected columns from datatable using LINQ

Avatar of kravindra
kravindra asked on
.NET Programming
3 Comments1 Solution670 ViewsLast Modified:
I am passing datatable instance to the dataadapter to fetch the resultset from database.the datatable default it doesn't any schema.

Datatable dt = new DataTable();

datadapter da = new dataadapter();


               var fundsReceiptsbatchids = (from batchids in dt.AsEnumerable()
                                            select new
                                                FUNDS_RECEIPT_BATCH_ID =

when i try to excute this LINQ query, I am getting an expection like
Specified cast is not valid.

I have question in  LINQ query  in select block I am assigning datatable column value
(i.e batchids.Field<int>("FUNDS_RECEIPT_BATCH_ID"))  to this field FUNDS_RECEIPT_BATCH_ID. i didn't mention this FUNDS_RECEIPT_BATCH_ID field in my class or anywhere.

Actually FUNDS_RECEIPT_BATCH_ID is a one of the column in my resultset, which i am fetching from database using dataadapter.

How to get the selected columns from datatable using LINQ?

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros