Hi,
I want a fast way to use assign a tha values in a DataTable to a
collection/Array/List of Classes. Each record in my DataTable should be new
Class, and tha Class would have property's for each Field in the DataTable.
Is something like this possible? Or how should I do something like this?
A more practical exemple:
I have a Class clsCustomer, which contains many orders: so a
Collection/Array/List of the clsOrder.
So with the CustomerID, I want to have the whole Collection/Array/List of
the clsOrder of this Customer...
Thanks a lot in advance,
Pieter
Jignesh Desai - 08 Aug 2005 14:27 GMT
Take a look into CollectionBase class
public class FeederCollection : CollectionBase
Regards
Jignesh Desai - MVP
Blogs @ http://dotnetjini.jigneshdesai.com/Blogs/default.aspx
.NET Training Programs : http://dotnetjini.jigneshdesai.com/Training.aspx
> Hi,
>
[quoted text clipped - 13 lines]
>
> Pieter
DraguVaso - 08 Aug 2005 14:43 GMT
Huh? What are you talking about? I din't find anything about a
"FeederCollection"? even when looking for it on google I din't find any
website!!
Are you sure that you write it like that? because I don't get a clue?
> Take a look into CollectionBase class
> public class FeederCollection : CollectionBase
[quoted text clipped - 23 lines]
> >
> > Pieter
Felix Braun - 08 Aug 2005 15:08 GMT
hello dragu,
sounds like you want to do O/R-mapping (object-relational-mapping). (Google
for that word for more help on this topic)
But maybe a typed dataset is just what you want. With a typed dataset you
can access the value of each column through a property.
regards,
Felix
> Huh? What are you talking about? I din't find anything about a
> "FeederCollection"? even when looking for it on google I din't find any
[quoted text clipped - 30 lines]
>> >
>> > Pieter
DraguVaso - 09 Aug 2005 09:13 GMT
Thanks! That object-relational-mapping stuf seems really nice to me! I have
to look a little bit further into that subject!
> hello dragu,
>
[quoted text clipped - 41 lines]
> >> >
> >> > Pieter
Cor Ligthert [MVP] - 08 Aug 2005 15:00 GMT
Pieter,
Assuming that you mean with classes instanced objects, than in my opinion is
your class on the same level as the arraylist or whatever.
And therefore is in my opinion just a for loop from the datatable, something
as
Dim myarraylist as new arraylist
For each row as datarow in myDatatable
dim myObject as new myClassBeNeLux
MyObject.TheCountry = col("Country")
if MyObject.TheCountry = "Belgium" then
MyObject.CorrectRoute = "Probably false"
end if
Next
In my opinion you cannot do it quicker using reflection or something what
you maybe expect You can maybe make a shorter routine using that, however
the processing time will probably be longer. You know something the same as
directing almost everybody except the first over a wrong route.
:-)
Cor
> Hi,
>
[quoted text clipped - 15 lines]
>
> Pieter
DraguVaso - 08 Aug 2005 15:17 GMT
Hehe ok thanks :-)
And your example was really nice and to the point! Great! (*tssssssssss*)
hehe :-)
> Pieter,
>
[quoted text clipped - 41 lines]
> >
> > Pieter
Ray Booysen - 08 Aug 2005 15:30 GMT
> Hi,
>
[quoted text clipped - 13 lines]
>
> Pieter
Dragu.
There is a solution using Reflection to map your column names to your
property name. It is a little in-depth but if you want to go down this
route, let me know.
Regards
Ray