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. Adding new Rows to the Data base table

Adding new Rows to the Data base table

Scheduled Pinned Locked Moved C#
tutorialquestionannouncement
4 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.
  • A Offline
    A Offline
    Ashraj1982
    wrote on last edited by
    #1

    Hi Can any one please tell me how to add the new rows to the existing table with the values using SqlAdapter and Data Row with out using insert statement. DataSet dset = new DataSet("DBTable"); DataTable dbtable = new DataTable("DBTable"); dset.Tables.Add(dbtable); SqlCommand dbcommand = new SqlCommand(); dbcommand.CommandText ="select * from DBTable"; dbcommand.Connection = myConnection; SqlDataAdapter dbDA = new SqlDataAdapter(dbcommand); dbDA.TableMappings.Add("Table", "DBTable"); dbDA.Fill(dset, "DBTable"); DataRow row; row = dbtable.NewRow(); row["FileName"] = DBfile; row["Meters"] = IMeter; dbtable.Rows.Add(row); dbDA.Update(dset); This above code throws exception called "Update requires a valid InsertCommand when passed DataRow collection with new rows." any Idea?

    L 1 Reply Last reply
    0
    • A Ashraj1982

      Hi Can any one please tell me how to add the new rows to the existing table with the values using SqlAdapter and Data Row with out using insert statement. DataSet dset = new DataSet("DBTable"); DataTable dbtable = new DataTable("DBTable"); dset.Tables.Add(dbtable); SqlCommand dbcommand = new SqlCommand(); dbcommand.CommandText ="select * from DBTable"; dbcommand.Connection = myConnection; SqlDataAdapter dbDA = new SqlDataAdapter(dbcommand); dbDA.TableMappings.Add("Table", "DBTable"); dbDA.Fill(dset, "DBTable"); DataRow row; row = dbtable.NewRow(); row["FileName"] = DBfile; row["Meters"] = IMeter; dbtable.Rows.Add(row); dbDA.Update(dset); This above code throws exception called "Update requires a valid InsertCommand when passed DataRow collection with new rows." any Idea?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      You need to add a SqlCommand for INSERT to the SqlDataAdapter (you have already done so for SELECT, but passing it to the constructor).**

      xacc.ide-0.1.3.14 - Now with syntax support for PowerShell
      xacc.ide-0.1.3.13 source code

      **

      R 1 Reply Last reply
      0
      • L leppie

        You need to add a SqlCommand for INSERT to the SqlDataAdapter (you have already done so for SELECT, but passing it to the constructor).**

        xacc.ide-0.1.3.14 - Now with syntax support for PowerShell
        xacc.ide-0.1.3.13 source code

        **

        R Offline
        R Offline
        rah_sin
        wrote on last edited by
        #3

        if u want to update db with dataadapters update method then u have to define adapters insert command with proper parameters. rahul

        L 1 Reply Last reply
        0
        • R rah_sin

          if u want to update db with dataadapters update method then u have to define adapters insert command with proper parameters. rahul

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          You should be replying to the original person asking the question :)**

          xacc.ide-0.1.3.14 - Now with syntax support for PowerShell
          xacc.ide-0.1.3.13 source code

          **

          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