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);
try
{
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]);
}
}