kravindra
asked on
How to display selected columns from datatable using LINQ
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_B ATCH_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_B ATCH_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?
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
}).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
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?
ASKER
We are using Oracle database. the type FUNDS_RECEIPT_BATCH_ID is NUMBER.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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