Can I discover which columns have changed for a DataRow in a DataT

G

Guest

I have a table that will not allow some values to be altered if the tuple
being updated meets certain requirements.

I have a stored procedure that individually updates each value in a tuple if
the relevant parameter is not null (all parameters default to null exept the
PK).

In this way I can use the stored proc to update non critical values (for
example descriptions) while the critical values are effectively locked. This
is fine when I deal with the data directly (ie without a DataTable).
when editable can use: sp_Update @id=1, @desc="xxx", @val=45
when not edit can only use: sp_Update @id=1, @desc="yyy", @val=dbnull

What I want to be able to do is update from a DataTable preferably using a
DataAdapter that will invoke the stored procedure with only the relevant
parameters for DataTable row.

In the DataTable it is possible to revert back to the original values by
calling DataTable.RejectChanges(). Is there some way that I can use this to
determine if particular values have changed for each DataTable row so that I
can invoke the stored procedure with only the relevant parameters? And if
this is possible is it also possible to make a DataAdapter sensitive to this?
 
V

Val Mazur \(MVP\)

Hi,

You could get chnaged DataRows using Select metgod of the DataTable and
specify options for the RecordState perameter. Not sure if this is what you
need
 
G

Guest

essentialy what I have done is
get the changes
iterate through the rows
iterate through the values comparing versions using something along the
lines of:
if(row[col,DataRowVersion.Original].Equals(row[col,DataRowVersion.Current]))
if they are equal I set the associated stored proc param to DBNull.Value
otherwise I set it to the value of row[col]

the only trouble I have so far is that I am including a small hack in that I
assume that the first parameter passed is alway going to be the PK and will
thus always be passed to the stored proc. I imagine I can get round this by
inspecting the constraints on the table at a later stage.
 

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

Top