473,503 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing Columns From A DataView

Hey folks,

I have a Global DataSet which I use across my application. I use a DataView
to give me the data that I want in a certain instance.

Is there a way I can create the DataView so that it has only some of the
columns of the DataSet (i.e. not all of them)?

If not, can I reorder the columns? Like, can I specify that I want "myCol"
to be the second column?

Thanks!
Nov 16 '05 #1
3 17552
John,

I assume you are talking about a datatable and not a dataset, because a
dataview is not related to a dataset.

A dataview is only a view on a datatable and holds only that plus the
sortorder and the rowfilter. So in my opinion would you have to use the
datatable for what you want.

Although I do not see the sense of reordering the columns, can you use a
remove, add, removeat unluckily not for you an insertat so you have to
rearange that using removeat and add them again yourself in my opinion.

http://msdn.microsoft.com/library/de...mberstopic.asp

I hope this helps?

Cor
Nov 16 '05 #2
John,

Like Cor said you have to accomplish this utilizing the datatable. If you
want to remove the column(s) in the view you will have to remove them from
the datatable then assign the view to the datatable. If you want to keep the
table in the original format you can simply copy the datatable to another
datatable from which you derive the dataview. I have included a sample below
to demonstrate my point.

I hope this helps.
---------------------------
//place code in a win form project with
//2 datagrids that have their default names
//this is using the Northwind db

SqlConnection conn = new SqlConnection(strConn);
DataSet ds_orig = new DataSet();
DataSet ds_copy = new DataSet();
DataTable dt;
DataView dv;

SqlDataAdapter da = new SqlDataAdapter("SELECT Title,FirstName,LastName FROM
Employees",conn);
da.Fill(ds_orig);
ds_copy = ds_orig.Copy();
dt = ds_copy.Tables[0];
dt.Columns.Remove("Title");
dv = new DataView(dt);

dataGrid1.DataSource = ds_orig;
dataGrid2.DataSource = dv;
Nov 16 '05 #3
Thx Cor and Brian. That's what I ended up doing (copying the datatable and
removing the columns from there).
"John Smith" <js@no.com> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
Hey folks,

I have a Global DataSet which I use across my application. I use a DataView to give me the data that I want in a certain instance.

Is there a way I can create the DataView so that it has only some of the
columns of the DataSet (i.e. not all of them)?

If not, can I reorder the columns? Like, can I specify that I want "myCol" to be the second column?

Thanks!

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
441
by: Deepa | last post by:
I have a dataset which am trying to sort by 3 specific columns. I am not making any connection to the database to get the dataset. I have the raw dataset already. What i tried doing was to create...
0
979
by: chrisben | last post by:
Hi, I made a DataTable table and add four DataColumn to it. Then I created a DataView by calling dbv=new DataView (table). Then I insert some rows to the dataview and bind it to my datagrid as...
2
1602
by: Karl Napp | last post by:
Hi NG, how to make a DataView show only selected COLUMNS? E.g: DataTable table // is already in memory and has two columns: "id" and "value" DataView view // should only show all rows from...
1
3425
by: sri_san | last post by:
Hello, I have a datagrid in which the header needs to span over 2 columns. I have tried creating a tableCells and tableRow at runtime and set the columnspan property of a cell to 2. But, the...
5
8811
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it...
0
2564
by: Bob Davies | last post by:
Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within a dataset, however upon attempting to create...
4
4705
by: Mortar | last post by:
i need a datagrid with 2 header columns. The top one might have 1 column spanning 5 columns of the header row below it. what is the best way to do this? Could i have 2 datatables...1 filling the...
4
4824
by: Simon Verona | last post by:
Normally Google is my friend, but I can't seem to work this one out. I'm sure it's really simple as well. I normally create a dataview from a table within a dataset using the ..defaultdataview...
1
1449
by: Richard Jonker | last post by:
Hi, I'm developing a webpage with a dataview. The data is retrieved from a database view. The columns in the dataview are created dynamically via a dataset. How can I add special columns like...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.