MyClassCollection = MyDataTable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DraguVaso

    MyClassCollection = MyDataTable

    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

    #2
    Re: MyClassCollecti on = MyDataTable

    Take a look into CollectionBase class
    public class FeederCollectio n : CollectionBase


    Regards
    Jignesh Desai - MVP
    Blogs @ http://dotnetjini.jigneshdesai.com/Blogs/default.aspx
    ..NET Training Programs : http://dotnetjini.jigneshdesai.com/Training.aspx


    "DraguVaso" <pietercoucke@h otmail.com> wrote in message
    news:uF4zgsBnFH A.3304@tk2msftn gp13.phx.gbl...[color=blue]
    > 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[/color]
    new[color=blue]
    > Class, and tha Class would have property's for each Field in the[/color]
    DataTable.[color=blue]
    >
    > 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
    >
    >[/color]


    Comment

    • DraguVaso

      #3
      Re: MyClassCollecti on = MyDataTable

      Huh? What are you talking about? I din't find anything about a
      "FeederCollecti on"? 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?


      "Jignesh Desai" <jignesh_desai@ hotmail.com> wrote in message
      news:eiLSI1BnFH A.1968@TK2MSFTN GP14.phx.gbl...[color=blue]
      > Take a look into CollectionBase class
      > public class FeederCollectio n : CollectionBase
      >
      >
      > Regards
      > Jignesh Desai - MVP
      > Blogs @ http://dotnetjini.jigneshdesai.com/Blogs/default.aspx
      > .NET Training Programs : http://dotnetjini.jigneshdesai.com/Training.aspx
      >
      >
      > "DraguVaso" <pietercoucke@h otmail.com> wrote in message
      > news:uF4zgsBnFH A.3304@tk2msftn gp13.phx.gbl...[color=green]
      > > 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[/color]
      > new[color=green]
      > > Class, and tha Class would have property's for each Field in the[/color]
      > DataTable.[color=green]
      > >
      > > 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[/color][/color]
      of[color=blue][color=green]
      > > the clsOrder of this Customer...
      > >
      > > Thanks a lot in advance,
      > >
      > > Pieter
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: MyClassCollecti on = MyDataTable

        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.TheCou ntry = col("Country")
        if MyObject.TheCou ntry = "Belgium" then
        MyObject.Correc tRoute = "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




        "DraguVaso" <pietercoucke@h otmail.com> schreef in bericht
        news:uF4zgsBnFH A.3304@tk2msftn gp13.phx.gbl...[color=blue]
        > 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
        >
        >[/color]


        Comment

        • Felix Braun

          #5
          Re: MyClassCollecti on = MyDataTable

          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

          "DraguVaso" <pietercoucke@h otmail.com> schrieb im Newsbeitrag
          news:uSWDq8BnFH A.240@TK2MSFTNG P10.phx.gbl...[color=blue]
          > Huh? What are you talking about? I din't find anything about a
          > "FeederCollecti on"? 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?
          >
          >
          > "Jignesh Desai" <jignesh_desai@ hotmail.com> wrote in message
          > news:eiLSI1BnFH A.1968@TK2MSFTN GP14.phx.gbl...[color=green]
          >> Take a look into CollectionBase class
          >> public class FeederCollectio n : CollectionBase
          >>
          >>
          >> Regards
          >> Jignesh Desai - MVP
          >> Blogs @ http://dotnetjini.jigneshdesai.com/Blogs/default.aspx
          >> .NET Training Programs : http://dotnetjini.jigneshdesai.com/Training.aspx
          >>
          >>
          >> "DraguVaso" <pietercoucke@h otmail.com> wrote in message
          >> news:uF4zgsBnFH A.3304@tk2msftn gp13.phx.gbl...[color=darkred]
          >> > 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[/color]
          >> new[color=darkred]
          >> > Class, and tha Class would have property's for each Field in the[/color]
          >> DataTable.[color=darkred]
          >> >
          >> > 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[/color][/color]
          > of[color=green][color=darkred]
          >> > the clsOrder of this Customer...
          >> >
          >> > Thanks a lot in advance,
          >> >
          >> > Pieter
          >> >
          >> >[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • DraguVaso

            #6
            Re: MyClassCollecti on = MyDataTable

            Hehe ok thanks :-)

            And your example was really nice and to the point! Great! (*tssssssssss*)
            hehe :-)


            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
            news:%23hRkxGCn FHA.3608@TK2MSF TNGP15.phx.gbl. ..[color=blue]
            > Pieter,
            >
            > Assuming that you mean with classes instanced objects, than in my opinion[/color]
            is[color=blue]
            > your class on the same level as the arraylist or whatever.
            >
            > And therefore is in my opinion just a for loop from the datatable,[/color]
            something[color=blue]
            > as
            >
            > Dim myarraylist as new arraylist
            > For each row as datarow in myDatatable
            > dim myObject as new myClassBeNeLux
            > MyObject.TheCou ntry = col("Country")
            > if MyObject.TheCou ntry = "Belgium" then
            > MyObject.Correc tRoute = "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[/color]
            as[color=blue]
            > directing almost everybody except the first over a wrong route.
            >
            > :-)
            >
            > Cor
            >
            >
            >
            >
            > "DraguVaso" <pietercoucke@h otmail.com> schreef in bericht
            > news:uF4zgsBnFH A.3304@tk2msftn gp13.phx.gbl...[color=green]
            > > 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[/color][/color]
            of[color=blue][color=green]
            > > the clsOrder of this Customer...
            > >
            > > Thanks a lot in advance,
            > >
            > > Pieter
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Ray Booysen

              #7
              Re: MyClassCollecti on = MyDataTable

              DraguVaso wrote:[color=blue]
              > 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
              >
              >[/color]
              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

              Comment

              • DraguVaso

                #8
                Re: MyClassCollecti on = MyDataTable

                Thanks! That object-relational-mapping stuf seems really nice to me! I have
                to look a little bit further into that subject!

                "Felix Braun" <fex@nexgo.de > wrote in message
                news:uichaKCnFH A.2444@tk2msftn gp13.phx.gbl...[color=blue]
                > hello dragu,
                >
                > sounds like you want to do O/R-mapping (object-relational-mapping).[/color]
                (Google[color=blue]
                > 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
                >
                > "DraguVaso" <pietercoucke@h otmail.com> schrieb im Newsbeitrag
                > news:uSWDq8BnFH A.240@TK2MSFTNG P10.phx.gbl...[color=green]
                > > Huh? What are you talking about? I din't find anything about a
                > > "FeederCollecti on"? 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?
                > >
                > >
                > > "Jignesh Desai" <jignesh_desai@ hotmail.com> wrote in message
                > > news:eiLSI1BnFH A.1968@TK2MSFTN GP14.phx.gbl...[color=darkred]
                > >> Take a look into CollectionBase class
                > >> public class FeederCollectio n : CollectionBase
                > >>
                > >>
                > >> Regards
                > >> Jignesh Desai - MVP
                > >> Blogs @ http://dotnetjini.jigneshdesai.com/Blogs/default.aspx
                > >> .NET Training Programs :[/color][/color][/color]
                http://dotnetjini.jigneshdesai.com/Training.aspx[color=blue][color=green][color=darkred]
                > >>
                > >>
                > >> "DraguVaso" <pietercoucke@h otmail.com> wrote in message
                > >> news:uF4zgsBnFH A.3304@tk2msftn gp13.phx.gbl...
                > >> > 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[/color][/color][/color]
                be[color=blue][color=green][color=darkred]
                > >> 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[/color][/color][/color]
                Collection/Array/List[color=blue][color=green]
                > > of[color=darkred]
                > >> > the clsOrder of this Customer...
                > >> >
                > >> > Thanks a lot in advance,
                > >> >
                > >> > Pieter
                > >> >
                > >> >
                > >>
                > >>[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                Working...