468,283 Members | 1,874 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,283 developers. It's quick & easy.

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 2580
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chris Ericoli | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.