Solved

Extracting column names from a DataView

Posted on 2008-10-03
2
3,348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 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