473,387 Members | 1,791 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,387 software developers and data experts.

Question on DataTable.Select()

Hello All,

I am trying to filter rows in a datatable based on filtercriteria and
sortcriteria using the datatable.select() method.

I am encountering a strange behavior in this process. Here is what I am
trying to do...

---------

1. Queried a table based on a filtercriteria and retrieved 40 rows into a
table in a dataset. Now my dataset's 0th table has 40 rows.

2. Now trying to select rows in the 0th table of the above dataset using a
filtercriteria.

Technically speaking if I run a select method over a parent table, resulting
child table should have less number of rows than parent table ....right? How
come my step 2 is returning 43 rows?

All I can conclude is select method is filtering the rows from the original
database table and not on the step 1 dataset's 0th table. I am sure that I am
using the correct syntax....

---

int noRowsParentTable = objDataSet.Tables[0].Rows.Count;

foundRows = objDataSet.Tables[0].Select("ID < 4600");

int noRowsChildTable = foundRows.Length;

----

noRowsParentTable = 211 rows
noRowsChildTable = 1327 rows

Can anyone please correct me? Or explain the strange behavior?

TIA,
Diffi
Nov 19 '05 #1
1 4010
This behaviour is not normal. I tested with a sample and everything worked
like we would expect...

Here's my complete code:
SqlConnection connection = new SqlConnection(CONNECTION_STRING);
SqlCommand command = new SqlCommand("SELECT * FROM Relevance", connection);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command);
try
{
da.Fill(ds);
}finally
{
connection.Dispose();
command.Dispose();
da.Dispose();
}
Response.Write(ds.Tables[0].Rows.Count);
Response.Write("-");
DataRow[] rows = ds.Tables[0].Select("RelevanceID < 4");
Response.Write(rows.Length);
Relevance table is just an ID and a Key

first one outputted 53, 2nd one outputted 4
Absolutely no clue on what's wrong with yours..are the objects (dataset,
datarow array) scopped locally? are they global and/or static..that's all I
could think of as potential culprits...

You should use a DataView and the Filter property for this stuff, though the
behaviour is still odd..

DataView dv = ds.Tables[0].DefaultView;
dv.Filter = "ID < 4";

and you'll see the filtered data from the original datatable (much like an
SQL view works)...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
Hello All,

I am trying to filter rows in a datatable based on filtercriteria and
sortcriteria using the datatable.select() method.

I am encountering a strange behavior in this process. Here is what I am
trying to do...

---------

1. Queried a table based on a filtercriteria and retrieved 40 rows into a
table in a dataset. Now my dataset's 0th table has 40 rows.

2. Now trying to select rows in the 0th table of the above dataset using a
filtercriteria.

Technically speaking if I run a select method over a parent table, resulting child table should have less number of rows than parent table ....right? How come my step 2 is returning 43 rows?

All I can conclude is select method is filtering the rows from the original database table and not on the step 1 dataset's 0th table. I am sure that I am using the correct syntax....

---

int noRowsParentTable = objDataSet.Tables[0].Rows.Count;

foundRows = objDataSet.Tables[0].Select("ID < 4600");

int noRowsChildTable = foundRows.Length;

----

noRowsParentTable = 211 rows
noRowsChildTable = 1327 rows

Can anyone please correct me? Or explain the strange behavior?

TIA,
Diffi

Nov 19 '05 #2

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

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
1
by: MrMike | last post by:
I have the following code which allows me to display records from a table named "lkup_Specie" in a datagrid. If I create a second datatable and a second hashtable for a table named "lkup_Grade",...
3
by: Bruno Rodrigues | last post by:
Hi all I'm using the following code standart in class libraries. I will not split this function in more layers, but I want to know if there are some architetural improvement to do in my code....
3
by: Peter | last post by:
Hi, I have two datatables and I want to efficiently query the intersection of the two using the studentID. In my example code below, I want to print out Mary and Jane and their exam grades and I...
10
by: Shawn Meyer | last post by:
Hello - I am trying to write a class that has an async BeginX and EndX, plus the regular X syncronous method. Delegates seemed like the way to go, however, I still am having problems getting...
6
by: Woody Splawn | last post by:
I have a Winform where I fill a table with an associated dataset. This will put say 20 records into the table. I know this is elemental but... I want to see only one record from on my Winform...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
1
by: Kevin S. Goff | last post by:
Someone asked me how I would do the following....suppose you have two ADO.NET datatables, and you want to do the equivalent of SELECT Table1.*, Table2.* (in other words, do a linq query that...
6
by: fniles | last post by:
I am using VB.NET 2005 and Access database. My program uses a timer that kicks in every 1 min to read from a database and copy the dataset table to a datatable. This database is in a class called...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.