How can I extract the column values of very first row in datatable using linq query?
Ex : there 2 row item
Xyz
Abc
I need to extract the first row value ie.,xyz
How can we achieve this using linq query
How can I extract the column values of very first row in datatable using linq query?
Ex : there 2 row item
Xyz
Abc
I need to extract the first row value ie.,xyz
How can we achieve this using linq query
you can try this it will pick all the row of xyz
dt.AsEnumerable().First()("Xyz").ToString()
You can try this as well :
DataRow firstRow = dataTable.AsEnumerable().FirstOrDefault();
Hi @yashashwini2322 ,
you can try:
getting the first row - returned as a list (of DataRows)
YourDataTableVar.AsEnumerable.Take(1).toList
Getting the first 1 column values as an array
YourDataTableVar.AsEnumerable.Take(1).Select(Function (x) x(YourColNameOrIndex).toString.Trim).toArray
regards,
Dim firstRowValue As String = (From row In yourDataTable.AsEnumerable()
Select row.Field(Of String)("ColumnName")
).FirstOrDefault()
If Not String.IsNullOrEmpty(firstRowValue)
Then
' Use 'firstRowValue' as needed in your workflow
LogMessage("First Row Value: " & firstRowValue)
Else
LogMessage("DataTable is empty or the specified column doesn't exist.")
End If
Hope it helps!!
Try this:
outputValue = dt.AsEnumerable().First()("ColumnName").ToString()
Hello @yashashwini2322
Assuming you have a DataTable named “dt” with at least one row and one column
Dim firstValue As String = dt.AsEnumerable().Select(Function(row) row.Field(Of String)(“ColumnName”)).FirstOrDefault()
Check if the DataTable is not empty before accessing the value
If Not String.IsNullOrEmpty(firstValue) Then
Use “firstValue” in your workflow
LogMessage("First Value: " & firstValue)
Else
LogMessage(“DataTable is empty or the column does not exist.”)
End If
Thanks & Cheers!!!
assign activity
str_output=datatable.rows(0)(“columnname”).tostring
gives you the first row value
no need of linq query
cheers
you can try this:
input_dt.AsEnumerable.Take(1).Select(Function (x) x(“xyz”).toString.Trim)
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.