動態|訪問|資料|數組|頁面|應用執行個體
用綁定一個 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]);
}
}