如何从数据表中获取行号? [英] How to get the row number from a datatable?

查看:55
本文介绍了如何从数据表中获取行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历数据表中的每一行:

I am looping through every row in a datatable:

foreach (DataRow row in dt.Rows) {}

我想获取dt数据表中当前行的索引。例如:

I would like to get the index of the current row within the dt datatable. for example:

int index = dt.Rows[current row number]

我该怎么做?

推荐答案

int index = dt.Rows.IndexOf(row);

但是您最好使用for循环而不是foreach。

But you're probably better off using a for loop instead of foreach.

这篇关于如何从数据表中获取行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆