/// <summary> ///1step: Defining entity Classes/// </summary> classPhonenum {intpId; Public intPId {Get{returnPId;} Set{pId =value;} } intPtypeid; Public intPtypeid {Get{returnPtypeid;} Set{Ptypeid =value;} } stringPName; Public stringPName {Get{returnPName;} Set{PName =value;} } stringPcellphone; Public stringPcellphone {Get{returnPcellphone;} Set{Pcellphone =value;} } stringPhomephone; Public stringPhomephone {Get{returnPhomephone;} Set{Phomephone =value;} } }
/// <summary> ///2step: How to define Conversions/// </summary> /// <param name= "DT" ></param> /// <returns></returns> Public StaticList<phonenum> getpnlist (DataTable DT)//defining static methods, passing DataTable parameters{List<PhoneNum> pnlist =NULL;//Define a list< entity class > set to be empty if(dt. Rows.Count >0)//determines whether the obtained DataTable has data, if any, instantiates the List<> collection, otherwise returns an empty collection{pnlist=NewList<phonenum>(); } Else { returnpnlist; } foreach(DataRow IteminchDt. Rows)//traversing rows in a DataTable{Phonenum temp=NewPhonenum ();//instantiate an entity classtemp. PId= (int) item["PID"];//assigning the corresponding field data in a DataTable row to an entity propertyTemp. Ptypeid = (int) item["Ptypeid"]; Temp. PName= item["pname"]. ToString (); Temp. Pcellphone= item["Pcellphone"]. ToString (); Temp. Phomephone= item["Phomephone"]. ToString (); Pnlist. ADD (temp); //list<> Collection Add assigned rows } returnPnlist;//returns the List<> collection after assignment}
DataSet DataSet is converted to a collection