Linq 合併資料表 用變數處理

P陳
各位好:
找到一個可以用LINQ 將兩個 Datatable 併成一個新的 Datatable,如下的第一段
但欄位部份,想用變數方式來產生以提高彈性,請問一下各位程式要如何修?
  Dim userRolesInfo2 = (From u In Users.AsEnumerable() Join ur In Userroles.AsEnumerable() On u.Field(Of Integer)("UserId") Equals ur.Field(Of Integer)("UserId")
                              Select dt.LoadDataRow((New Object() {u.Field(Of Integer)("UserId"),
                                  u.Field(Of String)("UserName"), ur.Field(Of Integer)("RoleId"),
                                  ur.Field(Of String)("RoleName")}), False)).ToList()

如 str1={u.Field(Of Integer)("UserId"),
u.Field(Of String)("UserName"), ur.Field(Of Integer)("RoleId"),
ur.Field(Of String)("RoleName")}


AllfieldS="u.Field(Of Integer)("UserId"),
                                  u.Field(Of String)("UserName"), ur.Field(Of Integer)("RoleId"),
                                  ur.Field(Of String)("RoleName")"
變成
Dim userRolesInfo2 = (From u In Users.AsEnumerable() Join ur In Userroles.AsEnumerable() On u.Field(Of Integer)("UserId") Equals ur.Field(Of Integer)("UserId")
                              Select dt.LoadDataRow((New Object() {AllFields}), False)).ToList()

回到頂部