MyClassCollection = MyDataTable

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

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
 
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?
 
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
 
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
 
Hehe ok thanks :-)

And your example was really nice and to the point! Great! (*tssssssssss*)
hehe :-)
 
DraguVaso said:
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
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
 
Thanks! That object-relational-mapping stuf seems really nice to me! I have
to look a little bit further into that subject!
 
Back
Top