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. Visual Basic
  4. How do you insert a row at a time?

How do you insert a row at a time?

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
4 Posts 4 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.
  • H Offline
    H Offline
    hounetdev
    wrote on last edited by
    #1

    Hello, I have a filled a data set and would like to insert data from that dataset to a different table then the dataset was filled with, is there a way to do it a row at a time? If so does anyone have an example?:confused: Thank you, Santana

    S G 2 Replies Last reply
    0
    • H hounetdev

      Hello, I have a filled a data set and would like to insert data from that dataset to a different table then the dataset was filled with, is there a way to do it a row at a time? If so does anyone have an example?:confused: Thank you, Santana

      S Offline
      S Offline
      super_coding
      wrote on last edited by
      #2

      Would you elaborate more? If I am correct, then this is what you want to happen: dataadapter.fill(dataset,"Table1") 'do inserts into the dataset 'now you want all the inserted rows to be saved to Table2! True? 'If you are using update command on dataadapter, then you would be able to only save the rows to Table1 dataadapter.update(dataset) 'this will save rows to Table1 if you want these rows to be saved into another table (Table2) then create another dataadapter + dataset for that table, copy dataset1 to dataset2 and then call update on dataadapter2. let me know. Web reading made easy - http://www.xemantex.com

      P 1 Reply Last reply
      0
      • S super_coding

        Would you elaborate more? If I am correct, then this is what you want to happen: dataadapter.fill(dataset,"Table1") 'do inserts into the dataset 'now you want all the inserted rows to be saved to Table2! True? 'If you are using update command on dataadapter, then you would be able to only save the rows to Table1 dataadapter.update(dataset) 'this will save rows to Table1 if you want these rows to be saved into another table (Table2) then create another dataadapter + dataset for that table, copy dataset1 to dataset2 and then call update on dataadapter2. let me know. Web reading made easy - http://www.xemantex.com

        P Offline
        P Offline
        Pradeep C
        wrote on last edited by
        #3

        You can use a command object to update the rows in Dataset to the second Table in database. 'assume connString = Your connection string Dim cn as new OledbConnection(connString) Dim cmd as new OledbCommand cmd.Connection = cn cn.Open dim i as integer For i=0 to DataSet1.Tables(0).Rows.Count-1 cmd.CommandText = "INSERT INTO Table2 (Col1,Col2,Col3,..) VALUES (DataSet1.Tables(0).Rows(i).Item(1),DataSet1.Tables(0).Rows(i).Item(2),DataSet1.Tables(0).Rows(i).Item(3)....) cmd.ExecuteNonQuery Next cn.Close cmd.Dispose cn.Dispose "I think there is a world market for maybe 5 computers" Thomas Watson, chairman of IBM, 1943 "There is no reason anyone would want a computer in their home" Ken Olson, chairman & founder of Digital equipment, 1977 "This 'telephone' has too many shortcomings to be seriously considered as a means of communication. The device is ingerently of no value to us." Western Union internal memo, 1876 "640 K ought to be enough for anybody." Bill Gates, 1981 "Computers in the future may

        1 Reply Last reply
        0
        • H hounetdev

          Hello, I have a filled a data set and would like to insert data from that dataset to a different table then the dataset was filled with, is there a way to do it a row at a time? If so does anyone have an example?:confused: Thank you, Santana

          G Offline
          G Offline
          Guerven
          wrote on last edited by
          #4

          try executing an SQL command using a command object. loop through the records in the dataset dim x as integer dim KKK as new oledbcommand kkk.connection = 'write you connection here kkk.connection.open ' if the connection is closed for x = 0 to dataset1.tables.rows.count - 1 kkk.executenonquery("Insert into TABLENAME (field1,field2,field3) values (" & dataset1.tables(x)("field1") & "," & dataset1.tables(x)("field2") & "," & dataset1.tables(x)("field3") & ")") next kkk.conection.close ' just close the connection - Casting More!! May elune shine upon you!

          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