如果是从数据库取得的,通过SELECT语句就可全成一个表。
另外可以用DataRelation进行关联。
private void CreateRelation() {
// Get the DataColumn objects from two DataTable objects in a DataSet.
DataColumn parentCol;
DataColumn childCol;
// Code to get the DataSet not shown here.
parentCol = DataSet1.Tables["Customers"].Columns["CustID"];
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
}
另外可以用DataRelation进行关联。
private void CreateRelation() {
// Get the DataColumn objects from two DataTable objects in a DataSet.
DataColumn parentCol;
DataColumn childCol;
// Code to get the DataSet not shown here.
parentCol = DataSet1.Tables["Customers"].Columns["CustID"];
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
}
拷贝过来
我的例子
public DataView GetSysLog()
{
String strsql;
DataSet myDs;
strsql="SELECT syslog.id as id, user0.username as name, syslog.desccontent as content, syslog.logdate as date FROM syslog INNER JOIN user0 ON syslog.loginname = user0.loginname order by syslog.logdate desc";
myDs=ExecuteSql4Ds(strsql);//自己读取数据的函数
return myDs.Tables[0].DefaultView ;
}
很清楚啊parentCol====>主表.列;childCol====>子表.列
看看这个:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingmasterdetailslistwithdatagrid.asp