473,662 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filtering a dataset?

I have a data set... in which i need to remove 1 row based on a particaly
name

eg

i have a data set (data) and it has 1 table and N rows.... It has a column
name of [name]
i want to remove all records where the [name] = 'any'

? how syntacically can i do that?

I came up with some hair brained idea.. (althnough it doesnt work.)
DataSet dlocation =
dataMan.CheckCa cheData(JR.Data Access.ContentT ype.Location);

DataRow[] dRow = dlocation.Table s[0].Select("text <> 'Any'");

dlocation.Table s[0].Rows.Clear();

dlocation.Table s[0].Rows = (DataRowCollect ion)dRow;

this.Location.D ataSource = dRow;

this.Location.D ataBind();

Any help would be great....
Nov 18 '05 #1
2 1242
The first thing that you need to do is find the row you want to delete, there are many ways you could do this but one way is to loop through all the rows looking for the one you need to delete based on this particular value you mention. Once you have a handle on the row you need to delete simply call the delete method on the row. e.g. workRow.Delete( );. I'm not sure what your snippet of code is trying to do but it looks like you may have a misconception in that your creating an array of datarows using the select method presumalbly to find the row you want to delete and then delete it, the problem with this is your array of data rows is in no way connected to the underlying datatable and hence you will only delete the row from the array not the datatable.

You should note that this does not physically remove the row from the datatable it just marks it for deletion by changing its row state, you need to call the AcceptChanges method on the datatable to remove it.

Hope this helps

"Darren Clark" wrote:
I have a data set... in which i need to remove 1 row based on a particaly
name

eg

i have a data set (data) and it has 1 table and N rows.... It has a column
name of [name]
i want to remove all records where the [name] = 'any'

? how syntacically can i do that?

I came up with some hair brained idea.. (althnough it doesnt work.)
DataSet dlocation =
dataMan.CheckCa cheData(JR.Data Access.ContentT ype.Location);

DataRow[] dRow = dlocation.Table s[0].Select("text <> 'Any'");

dlocation.Table s[0].Rows.Clear();

dlocation.Table s[0].Rows = (DataRowCollect ion)dRow;

this.Location.D ataSource = dRow;

this.Location.D ataBind();

Any help would be great....

Nov 18 '05 #2
thanx for the quick response..

What i was thinking would work (although i know now it doesnt) was to get
all the data i need first...
then run a select that should return all the rows that i would like.From
here the only way i could see to get them in a datable again is to run
importRow on each row

this seemed like it would be a waste of cycles... Why cant i just say here
is a array of Rows... IMPORT IT... anyway datasets cant do it..

When i first looked at the problem i was going to do it exactly the same way
as you have, however in some cases i have massive amounts of rows... and
doing a foreach over them would be a bit slow. So i was tyring to find
another way to do it.
If only you could cast a Datarow Array to a DataRowCollecti on and then run a
simple import...

Actually a great method of a dataset to go along with the table.Select()
method, would be a table.DeleteWhe re() type clause where you can type in
valid sql statements that would simply remove rows based on a query.

Anything is better than having to do a foreach to simply remove a few rows.

anyways just my 2 cents worth
daz
"Neil" <Ne**@discussio ns.microsoft.co m> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
The first thing that you need to do is find the row you want to delete, there are many ways you could do this but one way is to loop through all the
rows looking for the one you need to delete based on this particular value
you mention. Once you have a handle on the row you need to delete simply
call the delete method on the row. e.g. workRow.Delete( );. I'm not sure what
your snippet of code is trying to do but it looks like you may have a
misconception in that your creating an array of datarows using the select
method presumalbly to find the row you want to delete and then delete it,
the problem with this is your array of data rows is in no way connected to
the underlying datatable and hence you will only delete the row from the
array not the datatable.
You should note that this does not physically remove the row from the datatable it just marks it for deletion by changing its row state, you need
to call the AcceptChanges method on the datatable to remove it.
Hope this helps

"Darren Clark" wrote:
I have a data set... in which i need to remove 1 row based on a particaly name

eg

i have a data set (data) and it has 1 table and N rows.... It has a column name of [name]
i want to remove all records where the [name] = 'any'

? how syntacically can i do that?

I came up with some hair brained idea.. (althnough it doesnt work.)
DataSet dlocation =
dataMan.CheckCa cheData(JR.Data Access.ContentT ype.Location);

DataRow[] dRow = dlocation.Table s[0].Select("text <> 'Any'");

dlocation.Table s[0].Rows.Clear();

dlocation.Table s[0].Rows = (DataRowCollect ion)dRow;

this.Location.D ataSource = dRow;

this.Location.D ataBind();

Any help would be great....

Nov 18 '05 #3

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

Similar topics

3
3151
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if ds.table(0).rows(0).item("col1") = ds.table(1).rows(0).item("col2") then txtResult.text = ds.table(1).rows(0).item("col3")
3
2172
by: serge calderara | last post by:
Dear all, I have a csv file data which has been read and populate on a dataset object. then I need to bind part of the content of the dataset to a treeview control. I have read that XML format is particular usefull to be bind to a treeview as it handle nodes. So I have try to save my dataset content into a xml file. The content of that file is as follow : - <NewDataSet> - <REC_INFO>
0
3636
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a datagrid on the left side that lists names and perhaps a couple of other key fields. The user can click on a record in the datagrid, which should automatically pull up details on that record in the various text boxes and other controls on the right...
0
1181
by: Jenny C. | last post by:
Hi I am trying to do a SUM on a DataSet column with the following code // ds is the DataSet that I need to calculate data fro String filter2 = "EmpNo = " + this.EmpNo + " AND WEEK_ENDING >= '" + MyDateTime.Date.ToShortDateString() + "'" float totalGross = Convert.ToSingle(this.ds.Tables.Compute("SUM(GROSS)", filter2)) float totalEarn = Convert.ToSingle(this.ds.Tables.Compute("SUM(Earns)", filter2)) Here the problem: it doesn't...
2
3990
by: Marco Ippolito | last post by:
I have an offline DataSet: id (PK, sorted ASC), firstname, enabled 1, Aaron, true 2, Bill, false 3, Charlie, true .... 10001, Mike, false 10002, Nathan, false
0
1588
by: ber.janssens | last post by:
Hi, I am trying the new ObjectDataSource from ASP.NET 2.0. I connected a Gridview with ObjectDataSource which is connected to a webservice which returns a DataSet. In the Webmethod I return only the rows for the current page because paging is enabled, I use the parameters maximumRows and startRowIndex for doing this. I also got sorting to work using the parameter sortExpression. The method of the webservice looks like this:
7
14802
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
5
1905
by: LDD | last post by:
Hi Folks I'm trying to determine a way to handle paging, filtering and sorting in a datagrid. If I choose to filter and sort, I'd like to return a subset. If that resultset has more records then the number of rows I'd like to display, I'd like to be able to load pages into the grid. My question is, do I need to continually hit the db to get the next page of records, or is there another method of doing with the dataset. i.e. load the
2
3701
by: Jason Huang | last post by:
Hi, I use the ReadXML method in my C# Windows Form project. Here is some of my C# code: xmlDS.ReadXml(curDir + "\\Dept.xml") ; There're 20 rows and 5 columns in the Dept.xml. But now I just want some of the data in the Dept.xml, e.g., DeptLevel >1 AND Status=0. How do I filter the XML or xmlDS so that the output is what I need?
3
1859
by: Shawn Ramirez | last post by:
As with most web applications speed is a huge deal to me in my applications. My customers don't really care if my app is a true 3 tier application or not, they just want it to be faster then it was yesterday. Because of this I try to limit my calls to the database by using a loading lookup data for a customer and then filtering down to what I need. (I have alot of recursive logic because of alot of tree controls). Here is my question. ...
0
8435
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
8345
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
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
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...
1
8547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4181
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...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.