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

80酷酷网    80kuku.com

  动态|访问|数据|数组|页面|应用实例

用绑定一个 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]);
       }

  }

 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: