How to get only first row from the data table?

Hi All,

From the attachment I need to get the first row from the data table, please do needful on this.

@Yoichi
@ppr
@ushu
@Gokul001
Petrol.xlsx (6.4 KB)

From the datatable I need to get only:
Sep 25, 2023 ₹ 103.01 ₹ 0.28

Hi,

Can you try the following?

All the row item in a string

String.Join(" ",dt.Rows(0).ItemArray)

Each item

dt.Rows(0)("Price").ToString

(please change column name)

Regards,

Hello @Vrishchik

  1. Use the “Read Range” activity to read data from an Excel file into a DataTable. Configure the following properties:

    • Excel file path: YourExcelFile.xlsx
    • Range: A1:C1
    • Output DataTable: YourDataTable
  2. Assign activity to assign the first row to a DataRow variable:

    • Left: firstRow
    • Right: YourDataTable.Rows(0)
  3. Assign activity to concatenate and store the desired values in a string variable:

    • Left: resultText
    • Right: "Date: " & firstRow(“Date”).ToString() & ", Price: " & firstRow(“Price”).ToString() & ", Change: " & firstRow(“Change”).ToString()
  4. Use the “Log Message” activity to log the result:

    • Message: resultText

Thanks & Cheers!!!

can you check the column name in the data table exists or not if exists can you that its having space or not before the price or after the price

image

@Vrishchik

Hi

Try mentioning like this with column index position

In assign activity to get all values together in first row

str = String.Join(" ",dt.Rows(0).ItemArray)

If you want first row Price column value

Then in assign activity mention like

str = dt.Rows(0)(1).ToString

Instead of column name we are using index position where 0 is the index position for first column

Hope this helps

Cheers @Vrishchik

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.