473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.CheckCacheData(JR.DataAccess.ContentType.L ocation);

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

dlocation.Tables[0].Rows.Clear();

dlocation.Tables[0].Rows = (DataRowCollection)dRow;

this.Location.DataSource = dRow;

this.Location.DataBind();

Any help would be great....
Nov 18 '05 #1
2 1231
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.CheckCacheData(JR.DataAccess.ContentType.L ocation);

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

dlocation.Tables[0].Rows.Clear();

dlocation.Tables[0].Rows = (DataRowCollection)dRow;

this.Location.DataSource = dRow;

this.Location.DataBind();

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 DataRowCollection 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.DeleteWhere() 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**@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.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.CheckCacheData(JR.DataAccess.ContentType.L ocation);

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

dlocation.Tables[0].Rows.Clear();

dlocation.Tables[0].Rows = (DataRowCollection)dRow;

this.Location.DataSource = dRow;

this.Location.DataBind();

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
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...
3
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...
0
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...
0
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 >= '"...
2
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
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...
7
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...
5
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...
2
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...
3
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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
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...

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.