By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

DataTable.Select with custom class comparision

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.