DataSet DataSet into a collection

Source: Internet
Author: User

 /// <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.