PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Can I discover which columns have changed for a DataRow in a DataT

Reply

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

 
Thread Tools Rate Thread
Old 09-02-2006, 03:37 PM   #1
=?Utf-8?B?ZGljZQ==?=
Guest
 
Posts: n/a
Default Can I discover which columns have changed for a DataRow in a DataT


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?


  Reply With Quote
Old 10-02-2006, 11:19 AM   #2
Val Mazur \(MVP\)
Guest
 
Posts: n/a
Default Re: Can I discover which columns have changed for a DataRow in a DataT

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

--
Val Mazur
Microsoft MVP
http://xport.mvps.org


"dice" <dice@discussions.microsoft.com> wrote in message
news:3F8A9A47-0D68-4C0C-842C-157ECB3529A9@microsoft.com...
>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?
>
>



  Reply With Quote
Old 10-02-2006, 01:51 PM   #3
=?Utf-8?B?ZGljZQ==?=
Guest
 
Posts: n/a
Default RE: Can I discover which columns have changed for a DataRow in a DataT

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.
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off