如何知道,从DataTable对象的行索引 [英] How to know the row index from DataTable object

查看:282
本文介绍了如何知道,从DataTable对象的行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从DataGridView得到一个值,并根据特定的我想用DataTable对象以了解它的行索引。举例来说,如果我得到的价值这个,那么我想知道其在表中的索引。可我知道我应该怎么做

I'm getting a value from DataGridView, and based on particular I want to know its row index using DataTable object. For instance, if I get the value "this", then I want to know its index in table. May I know how should I done

推荐答案

如果说价值这一属于在<$ C $一个非主键列 C>数据表,你可能会得到多个行返回。

If that value "this" belongs to a Non-Primary-Key Column in DataTable, you may get more than one rows returned.

要找到 DataTable中的一个值,使用数据表选择()方法:

DataRow[] rows = dt.Select("Column1 = 'this'");

一旦你得到的行(S),你可以找到使用其指数 DataTable.Rows.IndexOf()方法。

我建议你找一个更好的方法来从数据表找到你行。可以使用属于一个主键列的值来查找行

I suggest you find a better way to locate your row from DataTable. May be look for row using a value that belongs to a Primary Key Column.

这将是巨大的,知道你为什么想这样做。有人能拿出一个更好的解决方案。

It would be great to know why you want to do this. Someone could come up with a better solution.

这篇关于如何知道,从DataTable对象的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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