V
Vance Kessler
I am wondering if there is a way to save a single DataRow in a DataSet. I
already have a reference to the DataRow I wish to save but I cannot see how
to update anything other than the entire DataSet.
Here is the reason I need to do this. I have designed some business objects
to use a DataRow (from a typed DataSet) to store the various settings for
each object. I also have a collection object which can hold a number of
these business objects. When using a collection all objects in that
collection use a shared DataSet to hold their data. When working with
single business objects, each one will have its own DataSet. All these
objects are fairly simple objects and do not span multiple tables. Is this
a reasonable approach? I am fairly new to ADO.NET.
This works fine for a single object when you want to save changes (it just
updates the single DataRow in its own DataSet). However, unexpected results
can occur when using a collection since they share a single DataSet.
Calling Save in a business object in a collection will actually save changes
to ALL business objects in that collection since they all share a single
DataSet which is not what I want. The collection object itself has a Save
method that will save the changes to all objects in the collection if that
is really what you wanted to do.
So, I would like to be able to Save changes to a single business object
without worrying whether it happens to be in a collection or not.
My initial thoughts are that maybe I could call GetChanges to generate a new
DataSet and then call RejectChanges on all the rows except the one I really
want to save. I could then call Update() and save that single row. Then I
would merge that dataset back into the original set. My concern is that by
calling RejectChanges on the other rows it would merge that information back
into the original DataSet and Reject those changes there as well.
Thanks
Vance
already have a reference to the DataRow I wish to save but I cannot see how
to update anything other than the entire DataSet.
Here is the reason I need to do this. I have designed some business objects
to use a DataRow (from a typed DataSet) to store the various settings for
each object. I also have a collection object which can hold a number of
these business objects. When using a collection all objects in that
collection use a shared DataSet to hold their data. When working with
single business objects, each one will have its own DataSet. All these
objects are fairly simple objects and do not span multiple tables. Is this
a reasonable approach? I am fairly new to ADO.NET.
This works fine for a single object when you want to save changes (it just
updates the single DataRow in its own DataSet). However, unexpected results
can occur when using a collection since they share a single DataSet.
Calling Save in a business object in a collection will actually save changes
to ALL business objects in that collection since they all share a single
DataSet which is not what I want. The collection object itself has a Save
method that will save the changes to all objects in the collection if that
is really what you wanted to do.
So, I would like to be able to Save changes to a single business object
without worrying whether it happens to be in a collection or not.
My initial thoughts are that maybe I could call GetChanges to generate a new
DataSet and then call RejectChanges on all the rows except the one I really
want to save. I could then call Update() and save that single row. Then I
would merge that dataset back into the original set. My concern is that by
calling RejectChanges on the other rows it would merge that information back
into the original DataSet and Reject those changes there as well.
Thanks
Vance