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();
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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()
Method 2
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"];
Method 3
@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]<div class="su-column su-column-size-1-2"><div class="su-column-inner su-u-clearfix su-u-trim"></div></div> ; // or string val = DataView[RowIndex]<div class="su-column su-column-size-1-2"><div class="su-column-inner su-u-clearfix su-u-trim"></div></div>.toString(); // (I didn't want to opt for boxing / unboxing) Correct me if I have misunderstood.
Method 4
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0