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. Passing data from datagrid to Dataset

Passing data from datagrid to Dataset

Scheduled Pinned Locked Moved Visual Basic
questiondatabase
6 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
    Danny van der Walt
    wrote on last edited by
    #1

    How can I get the changes made by a user to a datagrid's content to reflect in the "datasourced" dataset so that the database can be updated accordingly ? This is for a desktop program not asp. The dataset is filled by an SqlDataAdapter

    J 1 Reply Last reply
    0
    • D Danny van der Walt

      How can I get the changes made by a user to a datagrid's content to reflect in the "datasourced" dataset so that the database can be updated accordingly ? This is for a desktop program not asp. The dataset is filled by an SqlDataAdapter

      J Offline
      J Offline
      John Kuhn
      wrote on last edited by
      #2

      Isn't your DataGrid bound to the underlying DataSet? Shouldn't you be able to update the data source using the data adapter's update method? What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

      D 1 Reply Last reply
      0
      • J John Kuhn

        Isn't your DataGrid bound to the underlying DataSet? Shouldn't you be able to update the data source using the data adapter's update method? What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

        D Offline
        D Offline
        Danny van der Walt
        wrote on last edited by
        #3

        Any changes to the dataset reflects on the grid, but not visa versa. Either I am missing something, because it seems some intervention is needed. On the CurrentCellChanged event I have to add the following line (assuming the datasource is a dataset of course) Static PrevCell As DataGridCell Dim dsSender as Dataset dsSender.Tables(0).Rows(PrevCell.RowNumber).Item(PrevCell.ColumnNumber) = PrevCellData 'becomes prev cell on next itteration PrevCell = sender.CurrentCell Only then does ds.AcceptChanges and da.update(ds) work. I am not even talking about adding new records yet. Any suggestions to simplify the process would be appreciated.

        J 1 Reply Last reply
        0
        • D Danny van der Walt

          Any changes to the dataset reflects on the grid, but not visa versa. Either I am missing something, because it seems some intervention is needed. On the CurrentCellChanged event I have to add the following line (assuming the datasource is a dataset of course) Static PrevCell As DataGridCell Dim dsSender as Dataset dsSender.Tables(0).Rows(PrevCell.RowNumber).Item(PrevCell.ColumnNumber) = PrevCellData 'becomes prev cell on next itteration PrevCell = sender.CurrentCell Only then does ds.AcceptChanges and da.update(ds) work. I am not even talking about adding new records yet. Any suggestions to simplify the process would be appreciated.

          J Offline
          J Offline
          John Kuhn
          wrote on last edited by
          #4

          Danny, I apologize for my "shoot-from-the-hip" response to your question. It really isn't that simple, is it? Although I don't spend a whole bunch of time with Windows Forms, what I think has to be done with a DataGrid is to use BindingContext, create a new event handler, such as OnPositionChanged, and bind that handler to the PositionChanged event of the BindingContext. Then, in the event handler, you can decide whether or not you want to update the whole data set for a row change. Unfortunately, the examples I find of this method are really pretty trivial, though I haven't tried searching for information about them here on CodeProject yet. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

          D 1 Reply Last reply
          0
          • J John Kuhn

            Danny, I apologize for my "shoot-from-the-hip" response to your question. It really isn't that simple, is it? Although I don't spend a whole bunch of time with Windows Forms, what I think has to be done with a DataGrid is to use BindingContext, create a new event handler, such as OnPositionChanged, and bind that handler to the PositionChanged event of the BindingContext. Then, in the event handler, you can decide whether or not you want to update the whole data set for a row change. Unfortunately, the examples I find of this method are really pretty trivial, though I haven't tried searching for information about them here on CodeProject yet. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

            D Offline
            D Offline
            Danny van der Walt
            wrote on last edited by
            #5

            Apology accepted. Thing is, it IS as simple as your hip shot. The Grid DOES affect the datasource and visa versa. The dataset.acceptchanges statement just before the dataAdapter.updatedataset part appears to be the stoolsample in the applepie. It changes all rowstates from deleted, added to unchanged. Which in turn must be telling the adapter that nothing happened. Took out ds.acceptchanges and problem solved.

            J 1 Reply Last reply
            0
            • D Danny van der Walt

              Apology accepted. Thing is, it IS as simple as your hip shot. The Grid DOES affect the datasource and visa versa. The dataset.acceptchanges statement just before the dataAdapter.updatedataset part appears to be the stoolsample in the applepie. It changes all rowstates from deleted, added to unchanged. Which in turn must be telling the adapter that nothing happened. Took out ds.acceptchanges and problem solved.

              J Offline
              J Offline
              John Kuhn
              wrote on last edited by
              #6

              :cool: What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

              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