实现如下效果 部门人员信息表按照所在部门表进行分组显示,即部门表为主表,人员信息表为从表
则
//获取部门信息
DataSet ds = SqlHelper.ExecuteDataset(Pars.ConnStr, CommandType.Text, "SELECT BCK01 AS 部门ID,BCK03 AS 部门名称,BCK01A AS 父级ID FROM BCK1");
//获取人员信息
DataTable dtUser = SqlHelper.ExecuteDataset(Pars.ConnStr, CommandType.Text, "SELECT BCE01 AS UserID,BCE02 AS UserNo,BCE03 AS UserName,BCK01 AS DepID FROM BCE1").Tables[0];
//将人员信息表添加至部门信息表所在的dataSet
DataTable dtUserClone = dtUser.Clone();
dtUserClone.TableName = "dtUserClone";
for (int i = 0; i < dtUser.Rows.Count; i++)
{
dtUserClone.Rows.Add(dtUser.Rows[i].ItemArray);
}
ds.Tables.Add(dtUserClone);
//设置两表的主从关系