C#動態(tài)數(shù)組實用實例解析
作者:htw 
  C#動態(tài)數(shù)組實用實例向你介紹了一個DataList的三層代碼,希望通過一個C#動態(tài)數(shù)組實用實例對你理解和學(xué)習(xí)C#動態(tài)數(shù)組有所幫助。
 C#動態(tài)數(shù)組(ArrayList )應(yīng)用可以說在C#開發(fā)中是十分常用的,那么具體的實用實例是如何實現(xiàn)的呢?具體的實現(xiàn)步驟和注意事項是什么呢?
下面就是一個C#動態(tài)數(shù)組實例:用綁定一個DataList的三層代碼
C#動態(tài)數(shù)組之DAL 數(shù)據(jù)訪問層代碼:
- //綁定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;
 - }
 - }
 
C#動態(tài)數(shù)組之BLL業(yè)務(wù)層代碼:
- //綁定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;
 - }
 
C#動態(tài)數(shù)組之頁面層代碼:
- //綁定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]);
 - }
 - }
 
C#動態(tài)數(shù)組的應(yīng)用實例就向你介紹到這里,希望對你了解和學(xué)習(xí)C#動態(tài)數(shù)組有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡 
                    來源:
                    博客園
 














 
 
 
 
 
 
 