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. Web Development
  3. ASP.NET
  4. Copy rows from one datatable to another datatable

Copy rows from one datatable to another datatable

Scheduled Pinned Locked Moved ASP.NET
databasehelp
2 Posts 2 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.
  • D Offline
    D Offline
    DGtech
    wrote on last edited by
    #1

    DataSet ds = new DataSet(); DataTable dt = new DataTable("mytab"); DataColumn dc = new DataColumn("mycol", typeof(Int32)); dc.AutoIncrement=true; dt.Columns.Add(dc); ds.Tables.Add(dt); SqlDataAdapter da = new SqlDataAdapter("select * from authors",con); da.Fill(ds,"mytab"); dgrid.DataSource=ds.Tables["mytab"].DefaultView; dgrid.DataBind(); Now i want to select/filter some rows from the datatable "mytab" and copy that rows to other datatable say "mynewtab" and after that i want to insert rows from "mynewtab" to the database. I`ve used pubs database. I want only selected rows i.e (mycol <=2) from "mytab" and copy those rows to "mynewtab" and then insert rows from "mynewtab" to some other database table. Please help me.

    G 1 Reply Last reply
    0
    • D DGtech

      DataSet ds = new DataSet(); DataTable dt = new DataTable("mytab"); DataColumn dc = new DataColumn("mycol", typeof(Int32)); dc.AutoIncrement=true; dt.Columns.Add(dc); ds.Tables.Add(dt); SqlDataAdapter da = new SqlDataAdapter("select * from authors",con); da.Fill(ds,"mytab"); dgrid.DataSource=ds.Tables["mytab"].DefaultView; dgrid.DataBind(); Now i want to select/filter some rows from the datatable "mytab" and copy that rows to other datatable say "mynewtab" and after that i want to insert rows from "mynewtab" to the database. I`ve used pubs database. I want only selected rows i.e (mycol <=2) from "mytab" and copy those rows to "mynewtab" and then insert rows from "mynewtab" to some other database table. Please help me.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Why don't you just copy them in the database instead? insert into SomeOtherTable select * from mytab where mycol <= 2

      --- b { font-weight: normal; }

      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