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

DataTable.Select with custom class comparision

Hello,

I have a DataTable in which the items are of type MyClass.
How can I use Select to compare a MyClass instance with the DataTable?
Is there any overriden method (like the ToString()) to use it on
Select?

Thank you,
Nuno Magalhães.
Sep 29 '08 #1
3 2797
Nuno Magalhaes wrote:
I have a DataTable in which the items are of type MyClass.
How can I use Select to compare a MyClass instance with the DataTable?
Is there any overriden method (like the ToString()) to use it on
Select?
The DataTable .Select() can only be used to select items based on column
values. You can use the "Convert" operator to cast columns, but you cannot
operate on entire rows. You'll have to do it manually by enumerating the rows.

If you have .NET 3.5 you can just .Cast() the elements and use the LINQ
..Select() rather than the DataTable .Select(), which is more powerful and
gives you compile-time checking.

--
J.
Sep 29 '08 #2
Thanks for the reply.
So the unique method (using framework 1.1 and datatable) is to do
enumerate the rows and compare manually?
Suppose I have a class MyClass (and just want to compare one attribute
of that class) how can I use the Convert. Can you show me an example?

Thanks,
Nuno Magalhães.

On 29 Set, 17:01, Jeroen Mostert <jmost...@xs4all.nlwrote:
Nuno Magalhaes wrote:
I have a DataTable in which the items are of type MyClass.
How can I use Select to compare a MyClass instance with the DataTable?
Is there any overriden method (like the ToString()) to use it on
Select?

The DataTable .Select() can only be used to select items based on column
values. You can use the "Convert" operator to cast columns, but you cannot
operate on entire rows. You'll have to do it manually by enumerating the rows.

If you have .NET 3.5 you can just .Cast() the elements and use the LINQ
.Select() rather than the DataTable .Select(), which is more powerful and
gives you compile-time checking.

--
J.
Sep 29 '08 #3
Nuno Magalhaes wrote:
So the unique method (using framework 1.1 and datatable) is to do
enumerate the rows and compare manually?
Suppose I have a class MyClass (and just want to compare one attribute
of that class) how can I use the Convert. Can you show me an example?
Convert operates on columns. If the comparison you want to make is on a
column value, you can use .Select(). If it's on a custom property of MyClass
(not a column) you can't use .Select().

--
J.
Sep 29 '08 #4

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

Similar topics

2
by: Clinton Pierce | last post by:
I've filled a DataTable with columns that have custom type (a class that I'm using to keep track of other things, not just a value). When the .Select method goes to sort this column, how do I let...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
9
by: VMI | last post by:
We have this huge application that's based on storing tons of data on a dataTable. The only problem we're having is that storing LOTS of data (1 million records) into a datatable will slow down the...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
6
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to...
3
by: Phill W. | last post by:
OK, I've asked nicely before; now I'm going to throw down the gauntlet to anyone brave enough to take it up. In VB'2005, can anyone write me a class that inherits from System.Data.DataTable, add...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
8
by: Mantorok | last post by:
Hi all I'm populating a DataTable with around 1,500,000 rows, the table contains 4 columns, 3 string columns and a decimal column. However, I keep getting OutOfMemory exceptions when my app...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.