What does it mean of (0) in datable select function?

Example here

dt.Rows.IndexOf(dt.Select(" [name]='kate' ")(0)).ToString

I need to know what is the purpose of (0) because, this function couldn’t leave without it include if even if I try to change (0) to (1) I still getting an errors like this.

Here is details

Thanks,
Rugpong

@lovepong66

(0) will get the first datarow from the selected list or the filtered list
(1) will work but as per your error …your select is getting you only one row so it is failing with index out of bound means the index you gave which is 1 is for second row and there is no second row

Select will return enumerable of datarows means a collection of datarows which satisfy the given condition

Hope this clears

cheers

1 Like

Hi,

DataTable.Select method returns DataRow array and it’s necessary to indicate index number.

image

In this case, the following may be better because there is no error if dt.Select returns no rows.

dt.Rows.IndexOf(dt.Select(" [name]='kate' ").FirstOrDefault()).ToString

Regards,

1 Like

I think i got it by testing here is an example

  1. Excel data
    image

  2. in assign activities


    to get row index then use it for target row for update the data.

  3. Result in excel will be like this
    image

That correct!!! for (0)

Then i try to understanding with your answer with another way to make me clear with how about (1)
(In my mind i think about array datatype concept) then i fixed a bit of code (0) to (1)

Excel template (I removed ‘yes’ out for make it clear)
image

Code

Result in excel
image

Good job man Thank you very much for your reply.
Rugpong

1 Like

Oh big thank for this solution. Thank you

1 Like

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