Do you mean this array?
Dim GroupValues As Integer() = q.SelectMany(Function(item) item.Values.Select(Function(v) CInt(v))).ToArray
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi
Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MyDataTable As New DataTable
MyDataTable.Columns.Add("id", GetType(Integer))
MyDataTable.Columns.Add("A")
MyDataTable.Columns.Add("B")
MyDataTable.Columns.Add("C")
MyDataTable.Rows.Add({1, "MV", "1x240", "Air Building"})
MyDataTable.Rows.Add({2, "MV", "1x240", "ACC Building"})
MyDataTable.Rows.Add({3, "LV", "1x240", "Swithgear "})
MyDataTable.Rows.Add({4, "Cable Tray", "20", "Swithgear"})
MyDataTable.Rows.Add({5, "Cable Tray", "30", "ACC"})
MyDataTable.Rows.Add({6, "Cable Tray", "60", "ACC"})
MyDataTable.Rows.Add({7, "JB", "10x10", "Admin"})
MyDataTable.Rows.Add({8, "JB", "20x10", "Admin"})
MyDataTable.Rows.Add({9, "Detector", "Smoke", "Admin"})
MyDataTable.Rows.Add({10, "Detector", "Beam", "ACC"})
MyDataTable.Rows.Add({11, "Detector", "Heat", "ACC"})
Dim columName As String = "A"
Dim q = From row In MyDataTable.AsEnumerable()
Group row("id") By key = row(columName) Into Group
Select New With {.Key = CStr(key.ToString()), .Values = Group.Select(Function(r) r).ToArray}
Dim GroupKey = q.Select(Function(item) item.Key).ToArray
Dim GroupValues As Integer()() = q.Select(Function(item) item.Values.ToArray)' This Line Error
End Sub
GroupValues = (0)={1,2} (1)={3} (2)={4,5,6} (3)={7,8} (4)={9,10,11}
Then how to convert two-dimensional array to one-dimensional?
dim ArrayOneDimensional as integer()=GroupValues
Do you mean this array?
Dim GroupValues As Integer() = q.SelectMany(Function(item) item.Values.Select(Function(v) CInt(v))).ToArray
Hi @Mansour_Dalir ,
If you want to get IDs as Integer(), you can refer the following code.
Dim columName As String = "A"
Dim q = From row In MyDataTable.AsEnumerable()
Group row("id") By key = row(columName) Into Group
Select New With {
.Key = CStr(key.ToString()),
.Values = String.Join(",", Group.Select(Function(r) CStr(r)))
}
Dim GroupKey = q.Select(Function(item) item.Key).ToArray
Dim GroupIds As Integer() = MyDataTable.AsEnumerable().Select(Function(row) CInt(row("id"))).ToArray()
'result= {1,2,3,4,5,6,7,8,9,10,11}
Dim GroupValues As String() = q.Select(Function(item) item.Values).ToArray()
'result= {"1,2","3","4,5,6","7,8","9","10,11"}
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.