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();
da.fill(dt);
var fundsReceiptsbatchids = (from batchids in dt.AsEnumerable()
select new
{
FUNDS_RECEIPT_BATCH_ID =
batchids.Field<int>("FUNDS_RECEIPT_BATCH_ID")
}).ToList();
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?
To your question, "I have question in LINQ query in select block I am assigning datatable column value
(i.e batchids.Field<int>("FUNDS
Make sure that the field FUNDS_RECEIPT_BATCH_ID in the datatbase is truely an int and not something else.
Fernando