首页 > 开发 > 综合 > 正文

C#中动态数组(ArrayList )应用实例子(三层代码:数据访问层,业务层,页面层)

2020-02-03 13:42:07
字体:
来源:转载
供稿:网友
中国最大的web开发资源网站及技术社区,

用绑定一个 datalist 的三层代码说明一下:


dal 数据访问层代码:
------------------------------------------------------------
//绑定idlist,显示所有人员列表
  public dataset selectidlistall()
  {
       string str = "select p_number,p_name from t_people";
       dataset ds = new dataset();

       mycon = new sqlconnection(dal.dalconfig.connectionstring);
       try
       {
        sqldataadapter mycomm = new sqldataadapter(str,mycon);
        mycomm.fill(ds,"t_people");   
               
        return ds;
       }
       catch(exception exc)
       {
        throw exc;
       }
  }


bll业务层代码:
----------------------------------------------------------------
//绑定idlist,显示所有人员列表
  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;
  }


页面层代码:
-----------------------------------------------------------------
//绑定idlist,显示所有人员列表
  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]);
       }

  }


 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表