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