C
cpnet
I previously used DataSets in a project where there was not backing
database, and now I'm trying to use a DataSet in a WinForms project that
needs to edit data in a SQL Server database, but I'm having problems.
My first problem is how to detect if anything has changed in the DataSet
that may need to be sent to the SQL Server database. Currently when I
initialize my WinForm, I'm iterating through all DataTables in the DataSet
and adding a handler to the RowChanged event. This hander will check
myDataSet.HasChanges() and then enable/disable some save and cancel buttons.
This doesn't seem to pick up all changes at the moment, and I'm also
wondering if there's a more efficient way to handle this?
My second issue is understanding when to use DataSet.AcceptChanges() vs.
SqlDataAdapter.Update(myDataSet). From what I've read, if I want to persist
changes in my DataSet to my Database, then I should never be calling
DataSet.AcceptChanges(), but instead must call the Update() method for every
SqlDataAdapter that may have changes in the corresponding DataTable? If I
use AcceptChanges() then my changes won't be persisted to my database right?
Update() doesn't seem to be working for me right now. I don't get errors,
but I also don't get changes in my SQL Server database. The DataAdapter
wizard generated stored procs for all of my commands (and I have a distinct
DataAdapter for each table that I'm working with). The DataSet I'm using is
strongly typed with a DataTable corresponding to each DataAdapter. I'm
assuming that since I have a strongly typed dataset, I can use
myFirstDataAdapter.Update(myDataSet), as opposed to
myFirstDataAdapter.Update(myDataSet, "sometable")?
TIA,
cpnet
database, and now I'm trying to use a DataSet in a WinForms project that
needs to edit data in a SQL Server database, but I'm having problems.
My first problem is how to detect if anything has changed in the DataSet
that may need to be sent to the SQL Server database. Currently when I
initialize my WinForm, I'm iterating through all DataTables in the DataSet
and adding a handler to the RowChanged event. This hander will check
myDataSet.HasChanges() and then enable/disable some save and cancel buttons.
This doesn't seem to pick up all changes at the moment, and I'm also
wondering if there's a more efficient way to handle this?
My second issue is understanding when to use DataSet.AcceptChanges() vs.
SqlDataAdapter.Update(myDataSet). From what I've read, if I want to persist
changes in my DataSet to my Database, then I should never be calling
DataSet.AcceptChanges(), but instead must call the Update() method for every
SqlDataAdapter that may have changes in the corresponding DataTable? If I
use AcceptChanges() then my changes won't be persisted to my database right?
Update() doesn't seem to be working for me right now. I don't get errors,
but I also don't get changes in my SQL Server database. The DataAdapter
wizard generated stored procs for all of my commands (and I have a distinct
DataAdapter for each table that I'm working with). The DataSet I'm using is
strongly typed with a DataTable corresponding to each DataAdapter. I'm
assuming that since I have a strongly typed dataset, I can use
myFirstDataAdapter.Update(myDataSet), as opposed to
myFirstDataAdapter.Update(myDataSet, "sometable")?
TIA,
cpnet