Solved

Extracting column names from a DataView

Posted on 2008-10-03
2
3,261 Views
Last Modified: 2013-12-17
I found an answer here that uses the DataView.Table property to get the column names.  This is valid if all of the columns are used in the DataView.  However, I have DataView instances that do not always show all of the columns.  Both the .Table property and the ToTable() method return a DataTable with ALL of the columns of the underlying table.  Is there a way to extract the column names from the DataView itself so that I can only show those that pertain to the DataView?  Is there some way to isolate that information?
0
Comment
Question by:burghboy
2 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22636716
try with the following:
Extract a row from the dataview, any.
this DataRow object has a DataTable property
Look at the components of this datatable

that is:

foreach (DataColumn col in yourview.Rows[0].DataTable.Columns)
{
        string name = col.Name
}
0
 

Accepted Solution

by:
burghboy earned 0 total points
ID: 22637128
Actually the correct way to get there is myView[0].Row.Table.Columns.  But it is a moot point.  I misinterpretted the data that was bweing sent to my part of the application.  I was under the impression that the displayed data (in a grid in another section of the app) showed ALL of the data in the DataView that my Excel export function received.  Some of the fields are not displayed and the information I am extracting from the underlying table is correct.  Thanks to those who put some brain on this one, but my question was bad to begin with.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question