How do I convert DataTable to List of Generic Type, when Type must be defined at runtime?
I found several example on stackOverflow, but all of these examples use predefined Generic Type to convert to list. In my case I don't have defined type, and Type must be determined at runtime.
In my case Generic Type needs to be Dynamically build with having DataTable columns as each property, and property type will be string.
string sqlQuery = "SELECT Z.Column2, A.Column1, C.* FROM Z LEFT JOIN A ON A.ID = Z.AId bla bla bla";
//SQL will be very complex due to joins, selectively picked column from different tables.
con.ConnectionString = "";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlQuery , con);
da.Fill(resultDt);
Now I need to Convert resultDT to List, where Type is determined at run time, and it varies when SQL query varies.
After playing around for couple of hours, I found the way to achieve my goal. This may not be the efficient way of doing but it worked for me.