C # code
/// <Summary> <br/> // convert the datatable to list <br/> /// </Summary> <br/> // <typeparam name = "T"> </typeparam> <br/> // <Param name = "DT"> </param> <br/> // <returns> </returns> <br/> Public static ilist <t> datatabletolist <t> (datatable DT) <br/>{< br/> If (Dt = NULL) <br/> return NULL; <br/> ilist <t> result = new list <t> (); <br/> for (Int J = 0; j <DT. rows. count; j ++) <br/>{< br/> T _ t = (t) activator. Createinstance (typeof (t); <br/> propertyinfo [] propertys = _ T. getType (). getproperties (); <br/> foreach (propertyinfo PI in propertys) <br/>{< br/> for (INT I = 0; I <DT. columns. count; I ++) <br/>{< br/> // assign values for attributes consistent with field names <br/> If (Pi. name. equals (DT. columns [I]. columnname) <br/>{< br/> If (DT. rows [J] [I]! = Dbnull. value) <br/>{< br/> If (Pi. propertytype. tostring () = "system. int32 ") <br/>{< br/> pi. setvalue (_ T, int32.parse (DT. rows [J] [I]. tostring (), null); <br/>}< br/> If (Pi. propertytype. tostring () = "system. datetime ") <br/>{< br/> pi. setvalue (_ T, convert. todatetime (DT. rows [J] [I]. tostring (), null); <br/>}< br/> If (Pi. propertytype. tostring () = "system. string ") <br/>{< br/> pi. setvalue (_ T, DT. rows [J] [I]. tostring (), null); <br/>}< br/> If (Pi. propertytype. tostring () = "system. boolean ") <br/>{< br/> pi. setvalue (_ T, convert. toboolean (DT. rows [J] [I]. tostring (), null); <br/>}< br/> else <br/> pi. setvalue (_ T, null, null); <br/> break; <br/>}< br/> result. add (_ T); <br/>}< br/> return result; <br/>}
PS: I haven't used the csdn blog for a few months. It's still difficult to learn from each other ....