I’m using VS2010 and C#. I have one DataTable which I want to convert to a List.
Suppose:
Table dt;
On run time want to create similar field from a datatable and fill fields in List.There is no existing class for list properties.
ListName=TableName
List property name=Table column name
List Property type=Table column type
List items=Table rows
Note: Recently work on EF.To fullfill my project requirement, need to give flexibility to use to input and execute ESQL at runtime .I don’t want to put this execute result on datatable or List<DataRow> ,want to put this result on list.
List has no existing class and property,don’t want to convert DataTable on list Type:DataRow
We are still not sure what are you trying to do, but if you want to create list of dynamic objects, you can try
dynamicThen you will have to assign values to that list through
ExpandoObjectAnd the you will have to Cast it to
IDictionaryto pass column names as properties.And then you can access list items like this
item.YourColumnNameHere’s a full example:
or linq also works of course for printing out the values:
this program will print out: