How to get a value from a column in a DataView?

后端 未结 4 1355
旧巷少年郎
旧巷少年郎 2021-01-04 23:48

I have a dataview defined as:

DataView dvPricing = historicalPricing.GetAuctionData().DefaultView;

This is what I have tried, but it return

4条回答
  •  半阙折子戏
    2021-01-05 00:27

    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("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"];
    

提交回复
热议问题