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. updating data from datagridview

updating data from datagridview

Scheduled Pinned Locked Moved C#
questionannouncement
5 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.
  • A Offline
    A Offline
    ahmed mega
    wrote on last edited by
    #1

    hello every body, i use a datagrid view bounded to a datasource, but i can't update the changes happens in it. although, i've added the insert, update & delete queries i also use a dataset with a tableAdapter . and this what iam doing in the onSaveButton_Click: try { dataGridView1.EndEdit(); this.visitorTableAdapter.Update(this.omvDataSet.visitor); omvDataSet.AcceptChanges(); MessageBox.Show("Changes saved successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } so, what is the right solution to accomplish what i want. Regards

    M 1 Reply Last reply
    0
    • A ahmed mega

      hello every body, i use a datagrid view bounded to a datasource, but i can't update the changes happens in it. although, i've added the insert, update & delete queries i also use a dataset with a tableAdapter . and this what iam doing in the onSaveButton_Click: try { dataGridView1.EndEdit(); this.visitorTableAdapter.Update(this.omvDataSet.visitor); omvDataSet.AcceptChanges(); MessageBox.Show("Changes saved successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } so, what is the right solution to accomplish what i want. Regards

      M Offline
      M Offline
      monstale
      wrote on last edited by
      #2

      hi, what's wrong now? code looks good, but you don't need to .AcceptChanges() because .Update() does it for you. ;-) kind regards

      A 1 Reply Last reply
      0
      • M monstale

        hi, what's wrong now? code looks good, but you don't need to .AcceptChanges() because .Update() does it for you. ;-) kind regards

        A Offline
        A Offline
        ahmed mega
        wrote on last edited by
        #3

        ok i removed .AcceptChanges() now i tried to delete then i had this exception: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows. regards

        M 1 Reply Last reply
        0
        • A ahmed mega

          ok i removed .AcceptChanges() now i tried to delete then i had this exception: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows. regards

          M Offline
          M Offline
          monstale
          wrote on last edited by
          #4

          Hi, are you sure you filled all commands of DataAdapter? There are InsertCommand, UpdateCommand, DeleteCommand and SelectCommand (last is filled by constructor, normally). ;-) King regards

          A 1 Reply Last reply
          0
          • M monstale

            Hi, are you sure you filled all commands of DataAdapter? There are InsertCommand, UpdateCommand, DeleteCommand and SelectCommand (last is filled by constructor, normally). ;-) King regards

            A Offline
            A Offline
            ahmed mega
            wrote on last edited by
            #5

            Hi, yes i did filled these commands by the dataset designer but, i found that i have to add them into the properties window by myself and now it's working. thanks for your help, i really appreciate it. Regards

            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