Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. copy column values from one table to another

copy column values from one table to another

Scheduled Pinned Locked Moved C#
help
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Glen Harvy 0
    wrote on last edited by
    #1

    Hi, I have two tables in the same dataset. What I want to do is select a row in table 1 and copy the values in some columns from table 1 to table 2. Should be easy and I think I'm making it difficult for myself with code like: DataRow[] dr = this.mycourtsDataSet1.Court1.Select("BookingDate = '" + bookingDate.ToShortDateString() + "'"); DataRow nr = this.mycourtsDataSet1.CourtSchedule.NewRow(); nr["Date"] = bookingDate; nr["Court"] = "1"; if (dr.Length > 0) { for (int i = 0; i < dr[0].ItemArray.Length; i++) { string test = dr[0].ItemArray.GetValue(i).ToString(); } etc ....... Any suggestions as to where I can find some help on this. TIA

    Glen Harvy

    I 1 Reply Last reply
    0
    • G Glen Harvy 0

      Hi, I have two tables in the same dataset. What I want to do is select a row in table 1 and copy the values in some columns from table 1 to table 2. Should be easy and I think I'm making it difficult for myself with code like: DataRow[] dr = this.mycourtsDataSet1.Court1.Select("BookingDate = '" + bookingDate.ToShortDateString() + "'"); DataRow nr = this.mycourtsDataSet1.CourtSchedule.NewRow(); nr["Date"] = bookingDate; nr["Court"] = "1"; if (dr.Length > 0) { for (int i = 0; i < dr[0].ItemArray.Length; i++) { string test = dr[0].ItemArray.GetValue(i).ToString(); } etc ....... Any suggestions as to where I can find some help on this. TIA

      Glen Harvy

      I Offline
      I Offline
      il_masacratore
      wrote on last edited by
      #2

      Have you tried using BeginEdit() and EndEdit() on new row before anf after making changes?

      Visit my blog at http://dotnetforeveryone.blogspot.com/

      G 1 Reply Last reply
      0
      • I il_masacratore

        Have you tried using BeginEdit() and EndEdit() on new row before anf after making changes?

        Visit my blog at http://dotnetforeveryone.blogspot.com/

        G Offline
        G Offline
        Glen Harvy 0
        wrote on last edited by
        #3

        It's making the change that I want help with, not how to save them.

        Glen Harvy

        I A 2 Replies Last reply
        0
        • G Glen Harvy 0

          It's making the change that I want help with, not how to save them.

          Glen Harvy

          I Offline
          I Offline
          il_masacratore
          wrote on last edited by
          #4

          Do you add the new data row in the second table?

          Visit my blog at http://dotnetforeveryone.blogspot.com/

          G 1 Reply Last reply
          0
          • I il_masacratore

            Do you add the new data row in the second table?

            Visit my blog at http://dotnetforeveryone.blogspot.com/

            G Offline
            G Offline
            Glen Harvy 0
            wrote on last edited by
            #5

            DataRow[] dr2 = this.mycourtsDataSet1.Court2.Select("BookingDate = '" + bookingDate.ToShortDateString() + "'"); DataRow nr1 = this.mycourtsDataSet1.CourtSchedule.NewRow(); nr1["Date"] = bookingDate; nr1["Court"] = "2"; if (dr2.Length > 0) { for (int i = 0; i < dr[0].ItemArray.Length; i++) { if (dr2[0].Table.Columns[i].ColumnName.ToString().StartsWith("T") && !Convert.IsDBNull(dr2[0].ItemArray.GetValue(i))) { nr1[dr2[0].Table.Columns[i].ColumnName.ToString()] = Convert.ToDouble(dr2[0].ItemArray.GetValue(i)); } } } this.mycourtsDataSet1.CourtSchedule.Rows.Add(nr1); this.courtScheduleTableAdapter.Update(mycourtsDataSet1.CourtSchedule); mycourtsDataSet1.AcceptChanges();

            Glen Harvy

            1 Reply Last reply
            0
            • G Glen Harvy 0

              It's making the change that I want help with, not how to save them.

              Glen Harvy

              A Offline
              A Offline
              Andrei Ungureanu
              wrote on last edited by
              #6

              dr.AcceptChanges();

              Do your best to be the best

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups