DataTable操作相关实例
生活随笔
收集整理的這篇文章主要介紹了
DataTable操作相关实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼 ????????public?DataSet?GetChildDepartmentsByUserId(Guid?userId)?
????????{
????????????DataSet?ds?=?new?DataSet();
????????????try?
????????????{
????????????????OrgChartDB.OrgChart_PermissionDataTable?pdt?=?permissionTableAdapter.GetDataByUserId(userId);
????????????????for?(int?i?=?0;?i?<?pdt.Rows.Count;?i++)
????????????????{
????????????????????Guid?deptId?=?pdt[i].DepartmentId;
????????????????????OrgChartDB.OrgChart_DepartmentsDataTable?ddtAllChildDepartments?=?departmentsTableAdapter.GetChildDepartmentByDepartmentId(pdt.Rows[0][0]);
????????????????????ds.Tables.Add(ddtAllChildDepartments);
????????????????}
????????????????//OrgChartDB.OrgChart_DepartmentsDataTable?ddtAllChildDepartments?=?departmentsTableAdapter.GetChildDepartmentByDepartmentId(pdt.Rows[0][0]);
????????????????return?ds;
????????????}
????????????catch?(Exception?ex)?
????????????{
????????????}
????????}
????????{
????????????DataSet?ds?=?new?DataSet();
????????????try?
????????????{
????????????????OrgChartDB.OrgChart_PermissionDataTable?pdt?=?permissionTableAdapter.GetDataByUserId(userId);
????????????????for?(int?i?=?0;?i?<?pdt.Rows.Count;?i++)
????????????????{
????????????????????Guid?deptId?=?pdt[i].DepartmentId;
????????????????????OrgChartDB.OrgChart_DepartmentsDataTable?ddtAllChildDepartments?=?departmentsTableAdapter.GetChildDepartmentByDepartmentId(pdt.Rows[0][0]);
????????????????????ds.Tables.Add(ddtAllChildDepartments);
????????????????}
????????????????//OrgChartDB.OrgChart_DepartmentsDataTable?ddtAllChildDepartments?=?departmentsTableAdapter.GetChildDepartmentByDepartmentId(pdt.Rows[0][0]);
????????????????return?ds;
????????????}
????????????catch?(Exception?ex)?
????????????{
????????????}
????????}
根據一個datatable中的一列值獲取多個datatable并加入到dataset中。
注:此處pdt[i]返回PermissionDataRow能點出屬性。
pdt.rows[0].[i]返回DataRow,點不出屬性。
轉載于:https://www.cnblogs.com/hayden/archive/2010/01/29/1659061.html
總結
以上是生活随笔為你收集整理的DataTable操作相关实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jquery复习(七)之尺寸
- 下一篇: 如何将本地文件利用git工具上传到git