Posted in VB without a response, trying here.

  • Thread starter Thread starter John Wright
  • Start date Start date
J

John Wright

I have a class that I populate properties from a table in my database. I
create the properties in my class one for one with the columns in the tables
that I use to fill the class. Some properties are not loaded until a
function is called to load the properties when needed. In this class I have
about 50 properties that I expose to the client. The client, in turn, can
update most of the properties with new data, then call the update function.
So far so good.

However, I need to only update the properties that have changed. So I have
a Private Sub that records the table name, column name, old value, and new
value when a property is set and the values are different. This sub creates
a collection of property changes and then on the update I want to just send
the updates to the database.

Is there a better way to keep track of the properties that have changed for
the update function? I need to keep the old property value and the new
property value for auditing purposes. I was thinking of calling the
function on the property set function.

John
 
John,

You can use a DataRow/DataTable/DataSet. When you load the data into a
row, the RowState is equal to DataRowState.Unchanged. When you change any
of the values in the row, the state is changed to DataRowState.Modified.

When you normally deal with a DataRow, you are using the current values.
When you get a value using the indexer (the Item property), it is the same
as calling it with the string/integer/DataColumn instance, and passing a
value of DataRowVersion.Current.

If you want to get the original values, you can pass the
string/integer/DataColumn instance to the indexer, along with the
DataRowVersion.Original value to get the original values.

Or, if you want to work with two separate DataRow instances, you can
create a DataView on the DataTable, passing in the value of
DataViewRowState.OriginalRows to get the original values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top