如何从 DataView 的列中获取值?

发布于 2024-07-10 13:18:02 字数 227 浏览 4 评论 0原文

我有一个数据视图定义为:

DataView dvPricing = historicalPricing.GetAuctionData().DefaultView;

这是我尝试过的,但它返回名称,而不是列中的值:

dvPricing.ToTable().Columns["GrossPerPop"].ToString();

I have a dataview defined as:

DataView dvPricing = historicalPricing.GetAuctionData().DefaultView;

This is what I have tried, but it returns the name, not the value in the column:

dvPricing.ToTable().Columns["GrossPerPop"].ToString();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谢绝鈎搭 2024-07-17 13:18:02

您需要指定要获取其值的行。 我可能会更倾向于 table.Rows[index]["GrossPerPop"].ToString()

You need to specify the row for which you want to get the value. I would probably be more along the lines of table.Rows[index]["GrossPerPop"].ToString()

最丧也最甜 2024-07-17 13:18:02

您需要使用DataRow来获取值; 值存在于数据中,而不是列标题中。 在 LINQ 中,有一个扩展方法可能会有所帮助:

string val = table.Rows[rowIndex].Field<string>("GrossPerPop");

或者没有 LINQ:(

string val = (string)table.Rows[rowIndex]["GrossPerPop"];

假设数据字符串...如果不是,请使用 ToString()

如果您有一个 DataView 而不是 DataTable,那么同样适用于 DataRowView

string val = (string)view[rowIndex]["GrossPerPop"];

You need to use a DataRow to get a value; values exist in the data, not the column headers. In LINQ, there is an extension method that might help:

string val = table.Rows[rowIndex].Field<string>("GrossPerPop");

or without LINQ:

string val = (string)table.Rows[rowIndex]["GrossPerPop"];

(assuming the data is a string... if not, use ToString())

If you have a DataView rather than a DataTable, then the same works with a DataRowView:

string val = (string)view[rowIndex]["GrossPerPop"];
删除会话 2024-07-17 13:18:02

@马克·格拉维尔....
你的回答其实已经包含了这个问题的答案。
您可以从数据视图访问数据,如下所示

string val = (string)DataView[RowIndex][column index or column name in double quotes] ;
// or 
string val = DataView[RowIndex][column index or column name in double quotes].toString(); 
// (I didn't want to opt for boxing / unboxing) Correct me if I have misunderstood.

@Marc Gravell ....
Your answer actually has the answer of this question.
You can access the data from data view as below

string val = (string)DataView[RowIndex][column index or column name in double quotes] ;
// or 
string val = DataView[RowIndex][column index or column name in double quotes].toString(); 
// (I didn't want to opt for boxing / unboxing) Correct me if I have misunderstood.
━╋う一瞬間旳綻放 2024-07-17 13:18:02

对于 VB.NET 中的任何人:

Dim dv As DataView = yourDatatable.DefaultView
dv.RowFilter ="query " 'ex: "parentid = 1 "
for a in dv
  dim str = a("YourColumName") 'for retrive data
next

for anyone in vb.NET:

Dim dv As DataView = yourDatatable.DefaultView
dv.RowFilter ="query " 'ex: "parentid = 1 "
for a in dv
  dim str = a("YourColumName") 'for retrive data
next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文