Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27199

VS 2010 DataRowCollection to array

$
0
0
Hi all,
I have a datatable MYTABLE_U2U so formed:
Code:

    Cell_id                        adj
        A                          a1
        A                        a2
        A                        a3
        B                        b1
        B                        b2
        B                        b3


the elements number in second column can change.
So my goal is to select only adj elements when I specify Cell_id.
For i.e.:
vb.net Code:
  1. Dim tabella = From alldata In MYTABLE_U2U.AsEnumerable
  2.                                 Group By alldata!Cell_Id Into data = Group
  3.                                  Select Cell_Id, p = data.CopyToDataTable.Rows
  4.  
  5. Dim cc = ((From ele In tabella Where ele.Cell_Id ="A"
  6.                 Select dati = ele.p
  7.                 From ele1 In dati
  8.                 Select ele1.itemarray(0)).ToArray)

In this case cc contains a1,a2,a3

Now...
if I decided to create a datatable so:

vb.net Code:
  1. Dim table As DataTable = New DataTable
  2. table.Columns.Add("Cell_Id")
  3. table.Columns.Add("adj", GetType(System.Data.DataRowCollection))
  4. For Each ele In tabella
  5. table.Rows.Add(ele.Cell_Id, ele.p)
  6. Next

and then
vb.net Code:
  1. Dim cc_1 = ((From ele In table.Rows Where ele.ItemArray(0) = "A"
  2.         Select data = ele.itemarray(1)

cc_1 is a DataRowCollection but I cannot proceed to select elements of second column when Cell_Id="A"..
I tried several queries without success.
How can I convert datarowcollection into array of datarow?

thanks in advanced
Gio

Viewing all articles
Browse latest Browse all 27199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>