Select a column from a list array of type collection.generic.ienumerable(datatable)

I want to select one column inside the for each loop of a list array of the above type.

I am using the below query but I am not getting the value :
(item.AsEnumerable.Select(Function (x) (Convert.ToString (x.item(“Owner”))))).ToString

Could you please help me…

@debashishforyou,

what is your “item” datatype… is it the looping variable?

x.Item(“Owner”) - you need to check this, item will accept index where x is an array of string.
so instead of Owner you need to pass the index of Owner will work here?

yes, my item is the looping variable of type system.data.datatable.

I tried the below too…
(item.AsEnumerable.Select(Function (x) (Convert.ToString (x.item(4))))).ToString

But the output is coming as : System.data.emumerable.rowcollection`1[System.string]

The input column has values of 10, 20, 30 in excel (Number type - int)

@debashishforyou,

Can you share some sample of your input data for the loop. Like what is coming on the item and what you want to fetch out of it.

@debashishforyou

when you are looping over each datatable, each datatable can have 0,1 or more rows

Your statement item.AsEnumerable.Select(… will run over all rows of the datatable of the current iteration. And therefore its returning not a single value as it has to be ready for above (…each datatable can have 0,1 or more rows)

Just give us some more details on requirements and datasamples, so we can help you on this

Input.xlsx (8.5 KB)

PFA input file, All the values are in number format in excel.

I need all the values from column A one by one inside the loop. Currently I am getting System.data.emumerable.rowcollection`1[System.string] as output. I need the output as 0.00, 0.00…and so on

PFA input file, All the values are in number format in excel.

I need all the values from column A one by one inside the loop. Currently I am getting System.data.emumerable.rowcollection`1[System.string] as output. I need the output as 0.00, 0.00…and so on

PFA code sample from my sideTEST.xaml (12.9 KB)

@debashishforyou,

Check this xaml, it may help you. Let me know if you have any queries.
ReadExcelColumn.xaml (5.7 KB)

Hi,TEST.xaml (12.9 KB)

PFA my code sample, I need the id (distinct ID ) too which I already done here. I need to use this code (both id and that column value) as this values has to be updated to another sheet (using write range ) for that matching id in that sheet.

PLease help and suggest me changes in the attached file sample.

PFA input file, All the values are in number format in excel.

I need all the values from column A one by one inside the loop. Currently I am getting System.data.emumerable.rowcollection`1[System.string] as output. I need the output as 0.00, 0.00…and so on

PFA code sample from my sideTEST.xaml (12.9 KB)

@debashishforyou,
In your case you are looping with datatable, your looping argument also Datatable only.

So the query should be something like this.

(item.AsEnumerable.Select(Function (x) x.Field(Of String)("Owner")))

@debashishforyou
So give a try on item.AsEnumerable.Select(Function (x) x(“A”).ToString).ToArray()

and retrun from item - representing the datatable - an array of strings from Column A for each row belonging to this datatable

Still the same…

System.data.emumerable.rowcollection`1[System.string]

Not working for me

Tried…not working for me,can u please share a xaml file for me?

@debashishforyou
Had a look on your xaml
are you debugging and inspecting what my statement is returning in the locals panels or do you just refer on what your message box is giving with: result.tostring?

@debashishforyou
I had a look on one of your provided XAMLs during my lunch break. As I cannot refer to the excel data I have to guess and cannot crosscheck.

What @vickydas provided as hint should help you in your flow.

In general it seems to me that you are trying to implement a lookup for an EmployeeID into another DataTable. If my understanding is right, then your Implementation has a chance to get reduced to much less activities. A lookup e.g. can be easy implemented with a LINQ Join statement.

So just give us feedback if you got run your implementation. If you want my help on refactoring then provide me some more details on the requirments and the required excel files or demo data

This code only gives me the value of the first cell and for the next iteration it is throwing error as below :
Index was out of range. Must be non negative and less than the size of the collection