Dataset Table in Array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Sm9obiBSZWV2ZQ==?=

    Dataset Table in Array

    How to put a list of rows from dataset table into an array ?

    I tried with this code but it doesn't help.

    ArrayList arrayList = new ArrayList();
    foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
    {
    arrayList.Add (dr["Name"]);
    }


    --
    Regards,
    John Reeve
  • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

    #2
    Re: Dataset Table in Array

    John Reeve wrote:
    How to put a list of rows from dataset table into an array ?
    >
    I tried with this code but it doesn't help.
    >
    ArrayList arrayList = new ArrayList();
    foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
    {
    arrayList.Add (dr["Name"]);
    }
    >
    I don't know exactly what you want, as your code does something
    different from what you are asking for. This is closer to what you asked
    for:

    DataTable table = db.dataSetUsers .Tables["Functions"];
    DataRow[] rows = new DataRow[table.Rows.Coun t];
    int i = 0;
    foreach (DataRow row in table.Rows) {
    rows[i++] = row;
    }

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • =?Utf-8?B?Sm9obiBSZWV2ZQ==?=

      #3
      Re: Dataset Table in Array

      I want to add the names from database to an arraylist

      --
      Regards,
      John Reeve


      "Göran Andersson" wrote:
      John Reeve wrote:
      How to put a list of rows from dataset table into an array ?

      I tried with this code but it doesn't help.

      ArrayList arrayList = new ArrayList();
      foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
      {
      arrayList.Add (dr["Name"]);
      }
      >
      I don't know exactly what you want, as your code does something
      different from what you are asking for. This is closer to what you asked
      for:
      >
      DataTable table = db.dataSetUsers .Tables["Functions"];
      DataRow[] rows = new DataRow[table.Rows.Coun t];
      int i = 0;
      foreach (DataRow row in table.Rows) {
      rows[i++] = row;
      }
      >
      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      >

      Comment

      • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

        #4
        Re: Dataset Table in Array

        John Reeve wrote:
        I want to add the names from database to an arraylist
        >
        That's what your code is doing. In what way is it not helping?

        Tip: If you are top posting, you should not have two dashes in your
        signature. That is commonly regarded as end of message, so the news
        reader removes everything below it. As you are top posting that means
        the entire previous conversation.

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        • Ignacio Machin ( .NET/ C# MVP )

          #5
          Re: Dataset Table in Array

          On Jun 10, 1:47 am, John Reeve <john_ree...@ho tmail.comwrote:
          I want to add the names from database to an arraylist
          >
          --
          Regards,
          John Reeve
          >
          >
          >
          "Göran Andersson" wrote:
          John Reeve wrote:
          How to put a list of rows from dataset table into an array ?
          >
          I tried with this code but it doesn't help.
          >
          ArrayList arrayList = new ArrayList();
          foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
          {
          arrayList.Add (dr["Name"]);
          }
          >
          I don't know exactly what you want, as your code does something
          different from what you are asking for. This is closer to what you asked
          for:
          >
          DataTable table = db.dataSetUsers .Tables["Functions"];
          DataRow[] rows = new DataRow[table.Rows.Coun t];
          int i = 0;
          foreach (DataRow row in table.Rows) {
              rows[i++] = row;
          }
          >
          --
          Göran Andersson
          _____
          http://www.guffa.com- Hide quoted text -
          >
          - Show quoted text -
          As what? as string?
          List<stringname s = new List<string>();
          foreach (DataRow row in table.Rows) {
          names.Add( row["FirstName"].ToString());

          Comment

          • Ignacio Machin ( .NET/ C# MVP )

            #6
            Re: Dataset Table in Array

            On Jun 10, 7:30 am, Göran Andersson <gu...@guffa.co mwrote:
            John Reeve wrote:
            I want to add the names from database to an arraylist
            >
            That's what your code is doing. In what way is it not helping?
            Not really, the code just copy the ENTIRE column to an array, not very
            useful IMHO.

            Comment

            • =?ISO-8859-1?Q?G=F6ran_Andersson?=

              #7
              Re: Dataset Table in Array

              Ignacio Machin ( .NET/ C# MVP ) wrote:
              On Jun 10, 7:30 am, Göran Andersson <gu...@guffa.co mwrote:
              >John Reeve wrote:
              >>I want to add the names from database to an arraylist
              >That's what your code is doing. In what way is it not helping?
              >
              Not really, the code just copy the ENTIRE column to an array, not very
              useful IMHO.
              That depends on what the OP wants to do, which is what I am trying to
              find out...

              --
              Göran Andersson
              _____
              Göran Anderssons privata hemsida.

              Comment

              • =?Utf-8?B?TXVkYXNzYXIgSGFzc2Fu?=

                #8
                Re: Dataset Table in Array

                Try renaming the name of the arraylist; and it will works

                ArrayList arr = new ArrayList();
                foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
                {
                arr.Add (dr["Name"]);
                }


                Regards,
                Mudassar Hassan
                Technical endeavors to Microsoft Dynamics 365, Dynamics CRM, Azure and SharePoint



                "Göran Andersson" wrote:
                Ignacio Machin ( .NET/ C# MVP ) wrote:
                On Jun 10, 7:30 am, Göran Andersson <gu...@guffa.co mwrote:
                John Reeve wrote:
                >I want to add the names from database to an arraylist
                That's what your code is doing. In what way is it not helping?
                Not really, the code just copy the ENTIRE column to an array, not very
                useful IMHO.
                >
                That depends on what the OP wants to do, which is what I am trying to
                find out...
                >
                --
                Göran Andersson
                _____
                Göran Anderssons privata hemsida.

                >

                Comment

                • =?Utf-8?B?UmVldmU=?=

                  #9
                  Re: Dataset Table in Array

                  that works
                  thanks mudassar

                  --
                  Regards
                  Reeve - the developer

                  "Mudassar Hassan" wrote:
                  Try renaming the name of the arraylist; and it will works
                  >
                  ArrayList arr = new ArrayList();
                  foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
                  {
                  arr.Add (dr["Name"]);
                  }
                  >
                  >
                  Regards,
                  Mudassar Hassan
                  Technical endeavors to Microsoft Dynamics 365, Dynamics CRM, Azure and SharePoint

                  >
                  >
                  "Göran Andersson" wrote:
                  >
                  Ignacio Machin ( .NET/ C# MVP ) wrote:
                  On Jun 10, 7:30 am, Göran Andersson <gu...@guffa.co mwrote:
                  >John Reeve wrote:
                  >>I want to add the names from database to an arraylist
                  >That's what your code is doing. In what way is it not helping?
                  >
                  Not really, the code just copy the ENTIRE column to an array, not very
                  useful IMHO.
                  That depends on what the OP wants to do, which is what I am trying to
                  find out...

                  --
                  Göran Andersson
                  _____
                  Göran Anderssons privata hemsida.

                  Comment

                  • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

                    #10
                    Re: Dataset Table in Array

                    Mudassar Hassan wrote:
                    Try renaming the name of the arraylist; and it will works
                    >
                    ArrayList arr = new ArrayList();
                    foreach (DataRow dr in db.dataSetUsers .Tables["Functions"].Rows)
                    {
                    arr.Add (dr["Name"]);
                    }
                    >
                    >
                    Regards,
                    Mudassar Hassan
                    Technical endeavors to Microsoft Dynamics 365, Dynamics CRM, Azure and SharePoint

                    >
                    Why do you think that this would make any difference? Even if it may not
                    be ideal, the name arrayList is perfectly valid for an instance of the
                    class ArrayList.

                    --
                    Göran Andersson
                    _____
                    Göran Anderssons privata hemsida.

                    Comment

                    Working...