How to loop though datatable and save result in different datatable
I am using vb asp.net
Below I have 2 datatables and results
Dim NewDtatTable1 As DataTable = getResults()
Dim NewDtatTable2 As DataTable = NewDtatTable1
NewDtatTable1 Result:
|------------|--------|--------|
| myLocation | myName | date |
|------------|--------|--------|
| New york | name1 | 1/1/12 |
| Boston | name2 | 1/1/13 |
| New york | name3 | 1/1/14 |
| New york | name4 | 1/1/15 |
| Boston | name5 | 1/1/16 |
|------------|--------|--------|
i want to loop though datatable name NewDtatTable1 and if myLocation is equal to 'new york' than i want to add that row to new datatable NewDtatTable2
For Each row As DataRow In NewDtatTable21.Rows
If (String.Compare(row.Item("myLocation").ToUpper(), "NEW YORK", True) = 0)
Dim R As DataRow = NewDtatTable21.NewRow
NewDtatTable.Rows.Add(NewDtatTable1 .Rows.Item(row))
End If
End If
I want NewDtatTable2 result to be this:
|------------|--------|--------|
| myLocation | myName | date |
|------------|--------|--------|
| New york | name1 | 1/1/12 |
| New york | name3 | 1/1/14 |
| New york | name4 | 1/1/15 |
|------------|--------|--------|