Solved

Extracting column names from a DataView

Posted on 2008-10-03
2
3,214 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word Directory is not in the drop down list 4 25
Run time Error 4 34
Capture logon name 13 37
Variable Event ? 3 22
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now