PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Can I discover which columns have changed for a DataRow in a DataT
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Can I discover which columns have changed for a DataRow in a DataT
![]() |
Can I discover which columns have changed for a DataRow in a DataT |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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? > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

