How to get the row number from a datatable?

2020-02-02 11:50发布

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 the dt datatable. for example:

int index = dt.Rows[current row number]

How do i do this?

标签: c# datatable
7条回答
萌系小妹纸
2楼-- · 2020-02-02 12:17

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.

查看更多
登录 后发表回答