Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 20, 2013 09:13 AM by prabu.raveendran
Feb 19, 2013 05:55 AM|LINK
I am using Linq to SQL.I had dragged and dropped a stored procedure .
In interface i have
also i am using Repository to read datas i.e _port is repository.From repositor i call interface.
I want to convert this to datatable
It shows error
Unable to cast object of type 'System.Collections.Generic.List`1[RRPortal.Data_Access_Layer.SP_Validate_ITISAssociatesResult]' to type 'System.Data.DataTable'.
Feb 19, 2013 06:07 AM|LINK
The answer is you can't. It's not reasonable to convert a list of objects to datatable. You can iterate through the list and add rows to the datatable. There might be a different/better way to do this.
Feb 20, 2013 08:16 AM|LINK
As MetalAsp.Net said, you should convert list to datatable or dataset. Here is a sample:
Hope it can help you.
Feb 20, 2013 09:04 AM|LINK
You can iterate through the list and add rows to the datatable. To do so, visit this link to convert LINQ list intro datatable
Hope its help.
Feb 20, 2013 09:13 AM|LINK
To convert list to datatable you have to manually iterate all the elements and needs to add new datarow to the datatable. But it will affect you system performance.
Analyze the need for datatable instead of list of object check for the feasiblity of using list in your need.
If it is necessary to use Datatable then refer the below link,