Dynamic Array (ArrayList) application instance in C # (three-layer code: Data access layer, business layer, page layer)

Source: Internet
Author: User
Tags count tostring
Dynamic | access | data | array | page | Application Example

Use the three-layer code that binds a DataList to illustrate:

DAL Data Access Layer code:
Binding idlist, displaying a list of all people
Public DataSet Selectidlistall ()
String Str = "Select P_number,p_name from T_people";
DataSet ds = new DataSet ();

       mycon = new SqlConnection (DAL. dalconfig.connectionstring);
         SqlDataAdapter mycomm = new SqlDataAdapter (Str,mycon);
        Mycomm. Fill (ds, "T_people");   
        return ds;
       catch (Exception exc)
        throw exc;

BLL Business layer code:
//Binding idlist, displaying a list of all people
  Public arraylist  selectidlistall ()
       DAL. Tpeopledao Peopledao = new Tpeopledao ();
       DataSet ds = new DataSet ();
       ds = Peopledao. Selectidlistall ();

      //Creates and initializes a new ArrayList.
       ArrayList myal = new ArrayList ();
       for (int i=0;i<ds. Tables[0]. rows.count;i++)
        myal.add (ds. Tables[0]. Rows[i][0]. ToString () + "" +ds. Tables[0]. ROWS[I][1]. ToString ());           
       return myal;

Page Layer Code:
Binding idlist, displaying a list of all people
private void Selectidlistall ()
Lab.BLL.TPeopleBiz peoplebiz = new Tpeoplebiz ();
ArrayList Myal = peoplebiz. Selectidlistall ();
This. P_IDlist.Items.Clear ();

for (int i = 0; i<myal.count;i++)
This. P_IDLIST.ITEMS.ADD (Myal[i]);


Related Article

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.