Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Extracting column names from a DataView

Posted on 2008-10-03
2
Medium Priority
?
3,665 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

927 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