This example is about the use of DataList data-bound controls, because I was just learning this dongdong, so there is a wrong place to ask you advice ah.
ASP tutorial. NET code
private void Dataload ()
{
DataSet ds = new DataSet ();
String sql = "SELECT * from Partent";
SqlConnection con = new SqlConnection ("Data source=pc-200912151837;initial catalog=test;integrated security=true");
SqlDataAdapter da = new SqlDataAdapter (sql, con);
Da.fill (ds, "Xinghao");
String sql2 = "SELECT * from parent";
SqlDataAdapter da2 = new SqlDataAdapter (Sql2, con);
Da2.fill (ds, "parent");
That's the key, it seems, to create a relationship between 2 tables by ID, and then load the data
Ds.relations.add ("Myreation", ds.tables["son"].columns["son_id"], ds.tables["parent"].columns["parent_id"]);
Datalist.datasource = ds.tables["Son"].defaultview;
Datalist.databind ();
}
Database Tutorial Code:
CREATE table partent
( partent_id int not null primary key, Primary key id
Partent_name varchar () NOT NULL
)
Create Table son
(
son_id ID NOT null primary key, primary key tid
So N_name varchar null,
partent_id not null //partent associated with id
)