adding rows from one datatable to another

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

    #16
    Re: adding rows from one datatable to another

    Sam,

    In addition, I give you 3 solutions that can solve your problem. However I
    don't know your problem except that an original row cannot be added.

    Cor


    Comment

    • Cor Ligthert

      #17
      Re: adding rows from one datatable to another

      Sam,

      Quickly writen in this messages so watch typos or others.

      The first
      \\\
      dim dtnew as datatable = dtOld.Clone
      dtnew.rows.Add( dt.newrow)
      dtnew.importrow (dtOld.Rows(0))
      ///
      The second
      \\\
      dim dtnew as datatable = dtOld.Clone
      dtnew.rows.Add( dt.newrow)
      dim dr as datarow = dtnew.rows(0)
      dt.rows.remove( 0)
      dtnew.rows.Add( dr)
      ///
      The third
      \\\
      dim dv = new dataview(dtOld)
      'in a dv the show on a datarow is to get (as I showed you before) as a
      datarowview
      ///

      I hope this give some ideas

      Cor


      Comment

      • Sam

        #18
        Re: adding rows from one datatable to another

        Cor,

        All of these three methods have an issue.
        As I said before, my code is in a loop. I think it's a good idea I give
        the algorithm I'm trying to write so one can help me :

        for ........
        'reset dtFlows
        'fill dtFlows with values based on some requests

        'add rows of dtFlows to dtAllFlows (I know I can't do that directely)
        next

        Therefore, doing one of your two methods wouldn't work as I don't want
        to do
        dim dtnew as datatable = dtOld.Clone in each loop (that would delete
        all the existing rows added before)


        Your third method :
        dim dv = new dataview(dtOld)
        OK but I want to put my dv in a datatable then, how ? Actually to be
        more precise, I want to add this new datatable (dataview) to a dataset.

        Hope I'm clear enough.

        Sam

        Comment

        • Cor Ligthert

          #19
          Re: adding rows from one datatable to another

          Sam,

          You mean that you want to do this

          Dim ds as new dataset
          ds.tables.add(t ableOld.copy)

          Here the same isue, you cannot add a table to two dataset, because every
          datatable has a property dataset which can only hold one dataset.



          I know it is hard, I cannot change it.

          Cor


          Comment

          • Sam

            #20
            Re: adding rows from one datatable to another

            NOOOOOOOOOOOO !!!!!!! :-) I think we'll never understand each other on
            this one, LOL
            I don't want to add a table to two datasets. I just want to :

            loop
            reset datatable
            fill datatable with data

            fill newdatatable with rows of datatable above (here is the catch and
            I must find another way to do it, as you explained with a lot of effort
            that it's impossible ;-))

            next

            Then add newdatatable to a dataset (this is no problem at all)

            Hope this is clear ! Again as I'm in a loop I cannot do
            dim dtnew as datatable = dtOld.Clone
            as you mentionned before otherwise I would loose the data stored in
            dtnew that have been added in previous loops.

            Sam

            Comment

            • Cor Ligthert

              #21
              Re: adding rows from one datatable to another

              Sam,
              [color=blue]
              > NOOOOOOOOOOOO !!!!!!! :-) I think we'll never understand each other on
              > this one, LOL
              > I don't want to add a table to two datasets. I just want to :[/color]

              I know however what I showed you is the same as

              \\\
              dim dt as datatable = dtold.clone
              for each row as datarow in dtold
              dt.importrow(ro w)
              next
              ///

              However mayby you want to do it selective than you need this one.

              :-)

              Cor


              Comment

              • Hitesh

                #22
                Re: adding rows from one datatable to another

                hi guys..

                Pls be careful when using the below options if your appln architecture is
                using rowstates
                1) importrow does not modify the rowstate as added.

                2) methods like remove() are not advisable if what you want to do is just
                delete it is like calling delete and acceptchanges.

                3) i too did not understand this one..

                Tnx

                "Cor Ligthert" wrote:
                [color=blue]
                > Sam,
                >
                > Quickly writen in this messages so watch typos or others.
                >
                > The first
                > \\\
                > dim dtnew as datatable = dtOld.Clone
                > dtnew.rows.Add( dt.newrow)
                > dtnew.importrow (dtOld.Rows(0))
                > ///
                > The second
                > \\\
                > dim dtnew as datatable = dtOld.Clone
                > dtnew.rows.Add( dt.newrow)
                > dim dr as datarow = dtnew.rows(0)
                > dt.rows.remove( 0)
                > dtnew.rows.Add( dr)
                > ///
                > The third
                > \\\
                > dim dv = new dataview(dtOld)
                > 'in a dv the show on a datarow is to get (as I showed you before) as a
                > datarowview
                > ///
                >
                > I hope this give some ideas
                >
                > Cor
                >
                >
                >[/color]

                Comment

                Working...