通过索引检索 DataView 中的行
我有一个 DataView,它已按某种顺序排序。 如何使用索引检索值。
像这样的事情:
if(dv.rows[0]["name"]=="xxx")
{
--- do something ---
}
else
--- something else ---
I have a DataView, which has been sorted in some order. How can I retrieve the values using an index.
Something like this:
if(dv.rows[0]["name"]=="xxx")
{
--- do something ---
}
else
--- something else ---
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试以下代码
将排序后的 DataView 移动到 DataTable ,
然后使用
它将起作用。
Try the following code
Move the sorted DataView to DataTable like
Then use
It will work.
你试过了吗:
Did you try:
您可以直接使用 DataView,而不是将整个内容转换回 Table:
要从
DataView
获取行,您可以使用Item
属性,该属性返回一个DataRowView
,然后您可以调用Item
来获取单元格,所有这些都可以缩短为:Rather than converting the whole thing back to a Table, you can work with the DataView directly:
To get a row from a
DataView
, you use theItem
property, which returns aDataRowView
, and you can then callItem
to get at the cells, all of which can be shortened to:我不太知道这是否是您正在寻找的答案:
I don't quite know if this is the answer you're looking for:
我认为,直接使用 DataRowView 比将 dv 转换回 DataTable(它可能来自 DataTable)更简单。
var currRow = dv[0]; currRow["your_col_name"]?.ToString();
The direct use of the DataRowView is simpler than converting the dv back to a DataTable (where it probably came from to begin with), I think.
var currRow = dv[0]; currRow["your_col_name"]?.ToString();