473,659 Members | 2,690 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 17607
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(s trConn);
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.Remo ve("Title");
dv = new DataView(dt);

dataGrid1.DataS ource = ds_orig;
dataGrid2.DataS ource = 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******** ******@TK2MSFTN GP14.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 a DataView and sort it by a column name. mydataset.ReadXml(@sResponseXML); DataView mydataview = new DataView(); mydataview = ds.Tables.DefaultView; mydataview.Sort = "ColumnName";
0
982
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 dataGrid1.SetDataBinding(dbv,""); The problem is the columns are not filled into my datagrid
2
1611
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 "value"
1
3437
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 heading does not look good and is not aligned to the datagrid columns. Is there another way to do it? Any help would be great!! Thanks, Sam.
5
8824
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 happen. Dim objKeys(2) as Object objKeys(0) = "CL" objKeys(2) = 4000 Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
0
2586
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 tablestyles to format any of the columns within the datagrid, the exception "Can-not parent objects created on one thread to objects created on another" or words to that effect. I'm not too sure if what I said make sense, but i will add details to...
4
4713
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 top row, and the 2nd header row would come from the 2nd datatable? In this case, i guess i would have to add a row manually above the header row (2nd dataset) which is the set of 1st data? if someone has ideas, code explaining it would be very...
4
4832
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 method of the table (eg dv=ds.tables(0).defaultdataview) I want to create a dataview that is limited to only certain columns of the datatable. Anybody got a quick example to get me going?
1
1463
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 buttons and hyperlinks dynamically to the columns? When using MS Studio Developer you can add these columns via the property builder. In that case the first colums contains the buttons, I want them in the last columns.
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.