How to get the row number from a datatable?

前端 未结 7 1444
谎友^
谎友^ 2020-12-08 06:18

I am looping through every row in a datatable:

foreach (DataRow row in dt.Rows) {}

I would like to get the index of the current row within

7条回答
  •  孤街浪徒
    2020-12-08 07:06

    You have two options here.

    1. You can create your own index counter and increment it
    2. Rather than using a foreach loop, you can use a for loop

    The individual row simply represents data, so it will not know what row it is located in.

提交回复
热议问题