dataset table into an array list

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

    dataset table into an array list

    How to put a specified dataset table into an array list ?

    Hrcko


  • Adam Barker

    #2
    Re: dataset table into an array list

    arrayList.Add(" myArrayList", dSet.Tables["MyTable"]);


    "Hrvoje Voda" <hrvoje.voda@lu atech.com> wrote in message
    news:d7hsg9$6mf $1@ss405.t-com.hr...[color=blue]
    > How to put a specified dataset table into an array list ?
    >
    > Hrcko
    >[/color]


    Comment

    • Hrvoje Voda

      #3
      Re: dataset table into an array list

      I managed to fill an array, but I don't konw how to get a real informations
      from that array.

      When I try to fill a list with items from that array, I get:
      System.Collecti ons.ArrayList,
      and not the actual data.

      This is the code:

      ArrayList arrayList = new ArrayList();
      arrayList.Add (db.dataSetUser s.Functions);

      list.Items.Add( arrayList);

      Hrcko


      "Adam Barker" <adam@NO_SP_AM@ q-state.co.NO_SPA M.uk> wrote in message
      news:%23XN0e7eZ FHA.228@TK2MSFT NGP12.phx.gbl.. .[color=blue]
      > arrayList.Add(" myArrayList", dSet.Tables["MyTable"]);
      >
      >
      > "Hrvoje Voda" <hrvoje.voda@lu atech.com> wrote in message
      > news:d7hsg9$6mf $1@ss405.t-com.hr...[color=green]
      >> How to put a specified dataset table into an array list ?
      >>
      >> Hrcko
      >>[/color]
      >
      >[/color]


      Comment

      • Bjorn Abelli

        #4
        Re: dataset table into an array list

        "Hrvoje Voda" wrote...
        [color=blue]
        > I managed to fill an array, but I don't konw how to get
        > a real informations from that array.[/color]

        It's a bit confusing when you're using the word "array" when you mean an
        ArrayList (and v.v.)...
        [color=blue]
        > When I try to fill a list with items from that array,
        > I get: System.Collecti ons.ArrayList, and not the actual data.[/color]

        That is because you didn't "fill" the list with the actual items, but with
        the ArrayList instance.

        (I'm guessing that you really don't mean a "list", but a ListBox...)
        [color=blue]
        > list.Items.Add( arrayList);[/color]

        I'm not even sure you've got the contents of the ArrayList right, as I guess
        you "filled" it with some kind of collection of items, and not the items
        themselves?
        [color=blue]
        > arrayList.Add (db.dataSetUser s.Functions);[/color]

        So, what does the property "db.dataSetUser s.Functions" actually return?

        If it's some collection implementing the interface ICollection, I guess you
        rather want to use AddRange instead:

        arrayList.AddRa nge (db.dataSetUser s.Functions);

        ....and similarily when you put the *contents* of the ArrayList into the
        ListBox:

        list.Items.AddR ange( arrayList.ToArr ay() );

        There's even a possibility that you could skip the intermediate step of
        using the ArrayList, depending on what other use you have for it, and what
        kind of collection "db.dataSetUser s.Functions" is.

        Something like this should be possible:

        list.Items.Add( db.dataSetUsers .Functions.ToAr ray() );

        ....but as I said, that's depending on which type of collection the Functions
        property really is...


        // Bjorn A


        Comment

        • Hrvoje Voda

          #5
          Re: dataset table into an array list

          Functions is a name of the table in dataset.

          So, when I user ArrayList.AddRa nge it's an error.


          "Bjorn Abelli" <bjorn_abelli@D oNotSpam.hotmai l.com> wrote in message
          news:OHaROR1ZFH A.2756@tk2msftn gp13.phx.gbl...[color=blue]
          > "Hrvoje Voda" wrote...
          >[color=green]
          >> I managed to fill an array, but I don't konw how to get
          >> a real informations from that array.[/color]
          >
          > It's a bit confusing when you're using the word "array" when you mean an
          > ArrayList (and v.v.)...
          >[color=green]
          >> When I try to fill a list with items from that array,
          >> I get: System.Collecti ons.ArrayList, and not the actual data.[/color]
          >
          > That is because you didn't "fill" the list with the actual items, but with
          > the ArrayList instance.
          >
          > (I'm guessing that you really don't mean a "list", but a ListBox...)
          >[color=green]
          >> list.Items.Add( arrayList);[/color]
          >
          > I'm not even sure you've got the contents of the ArrayList right, as I
          > guess you "filled" it with some kind of collection of items, and not the
          > items themselves?
          >[color=green]
          >> arrayList.Add (db.dataSetUser s.Functions);[/color]
          >
          > So, what does the property "db.dataSetUser s.Functions" actually return?
          >
          > If it's some collection implementing the interface ICollection, I guess
          > you rather want to use AddRange instead:
          >
          > arrayList.AddRa nge (db.dataSetUser s.Functions);
          >
          > ...and similarily when you put the *contents* of the ArrayList into the
          > ListBox:
          >
          > list.Items.AddR ange( arrayList.ToArr ay() );
          >
          > There's even a possibility that you could skip the intermediate step of
          > using the ArrayList, depending on what other use you have for it, and what
          > kind of collection "db.dataSetUser s.Functions" is.
          >
          > Something like this should be possible:
          >
          > list.Items.Add( db.dataSetUsers .Functions.ToAr ray() );
          >
          > ...but as I said, that's depending on which type of collection the
          > Functions property really is...
          >
          >
          > // Bjorn A
          >
          >[/color]


          Comment

          • Bjorn Abelli

            #6
            Re: dataset table into an array list


            "Hrvoje Voda" wrote...[color=blue]
            > Functions is a name of the table in dataset.
            >
            > So, when I user ArrayList.AddRa nge it's an error.[/color]

            Of course it does, as DataTable doesn't implement ICollection.

            From your sparse comments one couldn't tell if the data from the table
            already was "transforme d" or "converted" in some way to a collection,
            reachable from the property db.dataSetUsers .Functions...

            So what you're saying is that db.dataSetUsers .Functions returns a DataTable?

            You still haven't said if you wanted the table as one single item in the
            ArrayList, or if you wanted the rows from the table to appear as items in
            the ArrayList...

            If you want the table juat as a single item, you can still use the
            "Add"-method (though it doesn't make much sense), but if you want the rows
            as separate items, you will most likely need to iterate through the table,
            and "Add" each item, e.g.

            foreach (DataRow dr in db.dataSetUsers .Functions.Rows )
            {
            // Form the row into something suitable
            // to be used in the ArrayList and/or ListBox
            // and add it...
            }


            // Bjorn A

            [color=blue]
            > "Bjorn Abelli" wrote...[color=green]
            >> "Hrvoje Voda" wrote...
            >>[color=darkred]
            >>> I managed to fill an array, but I don't konw how to get
            >>> a real informations from that array.[/color]
            >>
            >> It's a bit confusing when you're using the word "array" when you mean an
            >> ArrayList (and v.v.)...
            >>[color=darkred]
            >>> When I try to fill a list with items from that array,
            >>> I get: System.Collecti ons.ArrayList, and not the actual data.[/color]
            >>
            >> That is because you didn't "fill" the list with the actual items, but
            >> with the ArrayList instance.
            >>
            >> (I'm guessing that you really don't mean a "list", but a ListBox...)
            >>[color=darkred]
            >>> list.Items.Add( arrayList);[/color]
            >>
            >> I'm not even sure you've got the contents of the ArrayList right, as I
            >> guess you "filled" it with some kind of collection of items, and not the
            >> items themselves?
            >>[color=darkred]
            >>> arrayList.Add (db.dataSetUser s.Functions);[/color]
            >>
            >> So, what does the property "db.dataSetUser s.Functions" actually return?
            >>
            >> If it's some collection implementing the interface ICollection, I guess
            >> you rather want to use AddRange instead:
            >>
            >> arrayList.AddRa nge (db.dataSetUser s.Functions);
            >>
            >> ...and similarily when you put the *contents* of the ArrayList into the
            >> ListBox:
            >>
            >> list.Items.AddR ange( arrayList.ToArr ay() );
            >>
            >> There's even a possibility that you could skip the intermediate step of
            >> using the ArrayList, depending on what other use you have for it, and
            >> what kind of collection "db.dataSetUser s.Functions" is.
            >>
            >> Something like this should be possible:
            >>
            >> list.Items.Add( db.dataSetUsers .Functions.ToAr ray() );
            >>
            >> ...but as I said, that's depending on which type of collection the
            >> Functions property really is...
            >>
            >>
            >> // Bjorn A
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Hrvoje Voda

              #7
              Re: dataset table into an array list

              I tried to put all that I could remember into
              foreach()
              {
              ...
              }

              but I just can't find a code that will put a column names into an ArrayList.

              Hrcko


              "Bjorn Abelli" <bjorn_abelli@D oNotSpam.hotmai l.com> wrote in message
              news:ON%23oG02Z FHA.900@tk2msft ngp13.phx.gbl.. .[color=blue]
              >
              > "Hrvoje Voda" wrote...[color=green]
              >> Functions is a name of the table in dataset.
              >>
              >> So, when I user ArrayList.AddRa nge it's an error.[/color]
              >
              > Of course it does, as DataTable doesn't implement ICollection.
              >
              > From your sparse comments one couldn't tell if the data from the table
              > already was "transforme d" or "converted" in some way to a collection,
              > reachable from the property db.dataSetUsers .Functions...
              >
              > So what you're saying is that db.dataSetUsers .Functions returns a
              > DataTable?
              >
              > You still haven't said if you wanted the table as one single item in the
              > ArrayList, or if you wanted the rows from the table to appear as items in
              > the ArrayList...
              >
              > If you want the table juat as a single item, you can still use the
              > "Add"-method (though it doesn't make much sense), but if you want the rows
              > as separate items, you will most likely need to iterate through the table,
              > and "Add" each item, e.g.
              >
              > foreach (DataRow dr in db.dataSetUsers .Functions.Rows )
              > {
              > // Form the row into something suitable
              > // to be used in the ArrayList and/or ListBox
              > // and add it...
              > }
              >
              >
              > // Bjorn A
              >
              >[color=green]
              >> "Bjorn Abelli" wrote...[color=darkred]
              >>> "Hrvoje Voda" wrote...
              >>>
              >>>> I managed to fill an array, but I don't konw how to get
              >>>> a real informations from that array.
              >>>
              >>> It's a bit confusing when you're using the word "array" when you mean an
              >>> ArrayList (and v.v.)...
              >>>
              >>>> When I try to fill a list with items from that array,
              >>>> I get: System.Collecti ons.ArrayList, and not the actual data.
              >>>
              >>> That is because you didn't "fill" the list with the actual items, but
              >>> with the ArrayList instance.
              >>>
              >>> (I'm guessing that you really don't mean a "list", but a ListBox...)
              >>>
              >>>> list.Items.Add( arrayList);
              >>>
              >>> I'm not even sure you've got the contents of the ArrayList right, as I
              >>> guess you "filled" it with some kind of collection of items, and not the
              >>> items themselves?
              >>>
              >>>> arrayList.Add (db.dataSetUser s.Functions);
              >>>
              >>> So, what does the property "db.dataSetUser s.Functions" actually return?
              >>>
              >>> If it's some collection implementing the interface ICollection, I guess
              >>> you rather want to use AddRange instead:
              >>>
              >>> arrayList.AddRa nge (db.dataSetUser s.Functions);
              >>>
              >>> ...and similarily when you put the *contents* of the ArrayList into the
              >>> ListBox:
              >>>
              >>> list.Items.AddR ange( arrayList.ToArr ay() );
              >>>
              >>> There's even a possibility that you could skip the intermediate step of
              >>> using the ArrayList, depending on what other use you have for it, and
              >>> what kind of collection "db.dataSetUser s.Functions" is.
              >>>
              >>> Something like this should be possible:
              >>>
              >>> list.Items.Add( db.dataSetUsers .Functions.ToAr ray() );
              >>>
              >>> ...but as I said, that's depending on which type of collection the
              >>> Functions property really is...
              >>>
              >>>
              >>> // Bjorn A
              >>>
              >>>[/color]
              >>
              >>[/color]
              >
              >[/color]


              Comment

              • Bjorn Abelli

                #8
                Re: dataset table into an array list


                "Hrvoje Voda" wrote...
                [color=blue]
                >I tried to put all that I could remember into
                > foreach()
                > {
                > ...
                > }
                >
                > but I just can't find a code that will put a
                > column names into an ArrayList.[/color]

                If you want the column name from a specific column, you can get it through
                its index, e.g.:

                DataColumnColle ction columns =
                db.dataSetUsers .Functions.Colu mns;

                for (int i = 0; i < columns.Count; i++)
                {
                string colname = columns[i].ColumnName;
                // do something with the column name
                }


                // Bjorn A


                Comment

                • Hrvoje Voda

                  #9
                  Re: dataset table into an array list

                  Sorry, it's not column names but row names.
                  I tried to put DataRowCollecti on...
                  but I don't know how to get the row name.

                  Hrcko

                  "Bjorn Abelli" <bjorn_abelli@D oNotSpam.hotmai l.com> wrote in message
                  news:%23LYlFWBa FHA.3280@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                  >
                  > "Hrvoje Voda" wrote...
                  >[color=green]
                  >>I tried to put all that I could remember into
                  >> foreach()
                  >> {
                  >> ...
                  >> }
                  >>
                  >> but I just can't find a code that will put a
                  >> column names into an ArrayList.[/color]
                  >
                  > If you want the column name from a specific column, you can get it through
                  > its index, e.g.:
                  >
                  > DataColumnColle ction columns =
                  > db.dataSetUsers .Functions.Colu mns;
                  >
                  > for (int i = 0; i < columns.Count; i++)
                  > {
                  > string colname = columns[i].ColumnName;
                  > // do something with the column name
                  > }
                  >
                  >
                  > // Bjorn A
                  >
                  >[/color]


                  Comment

                  • Bjorn Abelli

                    #10
                    Re: dataset table into an array list


                    "Hrvoje Voda" wrote...
                    [color=blue]
                    > Sorry, it's not column names but row names.
                    > I tried to put DataRowCollecti on...
                    > but I don't know how to get the row name.[/color]

                    I don't understand what you mean here.

                    DataRows doesn't have names...

                    // Bjorn A


                    Comment

                    • Hrvoje Voda

                      #11
                      Re: dataset table into an array list

                      I don't want to get the names of columns but of their rows.

                      For example: The name of the column is FunctionName,
                      but in the row is "Function for all".

                      Hrcko


                      "Bjorn Abelli" <bjorn_abelli@D oNotSpam.hotmai l.com> wrote in message
                      news:%23SKkK%23 BaFHA.2496@TK2M SFTNGP14.phx.gb l...[color=blue]
                      >
                      > "Hrvoje Voda" wrote...
                      >[color=green]
                      >> Sorry, it's not column names but row names.
                      >> I tried to put DataRowCollecti on...
                      >> but I don't know how to get the row name.[/color]
                      >
                      > I don't understand what you mean here.
                      >
                      > DataRows doesn't have names...
                      >
                      > // Bjorn A
                      >
                      >[/color]


                      Comment

                      • Bjorn Abelli

                        #12
                        Re: dataset table into an array list


                        "Hrvoje Voda" wrote...
                        [color=blue]
                        >I don't want to get the names of columns but of their rows.
                        >
                        > For example: The name of the column is FunctionName,
                        > but in the row is "Function for all".[/color]

                        Let's see if I got this right...

                        So you *know* the column name...

                        You want the *content* of the column "FunctionNa me" from each row...

                        And then you want to add that to an ArrayList...

                        You could try this:

                        foreach (DataRow row in db.dataSetUsers .Functions.Rows )
                        {
                        string x = row["FunctionNa me"].ToString();
                        arrayList.Add ( x );
                        }


                        // Bjorn A


                        Comment

                        • Hrvoje Voda

                          #13
                          Re: dataset table into an array list

                          I tried that,

                          but when I fill a listbox with that arrayList I get :
                          System.Collecti on.ArrayList


                          "Bjorn Abelli" <bjorn_abelli@D oNotSpam.hotmai l.com> wrote in message
                          news:uI4JsnCaFH A.3536@TK2MSFTN GP10.phx.gbl...[color=blue]
                          >
                          > "Hrvoje Voda" wrote...
                          >[color=green]
                          >>I don't want to get the names of columns but of their rows.
                          >>
                          >> For example: The name of the column is FunctionName,
                          >> but in the row is "Function for all".[/color]
                          >
                          > Let's see if I got this right...
                          >
                          > So you *know* the column name...
                          >
                          > You want the *content* of the column "FunctionNa me" from each row...
                          >
                          > And then you want to add that to an ArrayList...
                          >
                          > You could try this:
                          >
                          > foreach (DataRow row in db.dataSetUsers .Functions.Rows )
                          > {
                          > string x = row["FunctionNa me"].ToString();
                          > arrayList.Add ( x );
                          > }
                          >
                          >
                          > // Bjorn A
                          >
                          >[/color]


                          Comment

                          • Bjorn Abelli

                            #14
                            Re: dataset table into an array list


                            "Hrvoje Voda" <hrvoje.voda@lu atech.com> skrev i meddelandet
                            news:d7pd79$hjh $1@ss405.t-com.hr...[color=blue]
                            >I tried that,
                            >
                            > but when I fill a listbox with that arrayList I get :
                            > System.Collecti on.ArrayList[/color]

                            Then you missed what I said previously in this thread...

                            list.Items.AddR ange(arraylist) ;


                            // Bjorn A


                            Comment

                            Working...