-2
 Dim rowD As DataRow() = argDatD.Select("No="+ rowS(0).ToString, String.Empty).ToArray

Please Explain the Code Snippet. I need to modify argDatD.Select("No="+ rowS(0).ToString, String.Empty).ToArray. Such that there is no column name in DataTable/Excel. In this case "No" is a column Head.I don't have any Column head. Please I'm new to VB. enter image description here

 argDatD.Select(argDatD.Columns(1).ColumnName + rowS(0).ToString, String.Empty).ToArray

enter image description here

nbk
  • 45,398
  • 8
  • 30
  • 47
abhishek
  • 9
  • 3
  • You don't need the column name to get the value of the DataRow, you can use the column-index. – Tim Schmelter Apr 12 '23 at 09:07
  • You will need to set a column name to be able to use it in a DataTable.Select filter expression, as far as I can see. – Andrew Morton Apr 12 '23 at 09:46
  • Can you tell me how can we use column-index in the above mentioned Code line. Consider the 0th column in the table.@TimSchmelter – abhishek Apr 12 '23 at 10:01
  • @abhishek: one way is using LINQ: `Dim rowD As DataRow() = argDatD.AsEnumerable().Where(Function(r) r[0].ToString() = rowS(0).ToString()).ToArray()` – Tim Schmelter Apr 12 '23 at 10:14

1 Answers1

0

The columns have default names if you don't name them. The first column (i.e. the one with an index of 0) is named "Column1". The second column (i.e. the column with an index of 1) is named "Column2", and so on. (See the "Remarks" section of the documentation for the DataColumn.ColumnName Property.)

So you just need to find out which column has the data you want to check for. For example:

Dim dt As New DataTable
dt.Columns.Add()
dt.Columns.Add()

dt.Rows.Add({"a", "b"})
' See the default name
Console.WriteLine(dt.Columns(1).ColumnName)

' Try a DataTable.Select
Dim a = dt.Select("Column2 = 'b'").ToArray()
Console.WriteLine(a(0)(0))

Outputs:

Column2
a
Andrew Morton
  • 24,203
  • 9
  • 60
  • 84