How to get the row number from a datatable?

前端 未结 7 1439
谎友^
谎友^ 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条回答
  •  旧时难觅i
    2020-12-08 06:48

    You do know that DataRow is the row of a DataTable correct?

    What you currently have already loop through each row. You just have to keep track of how many rows there are in order to get the current row.

    int i = 0;
    int index = 0;
    foreach (DataRow row in dt.Rows) 
    {
    index = i;
    // do stuff
    i++;
    } 
    

提交回复
热议问题