Groups | Blog | Home
all groups > dotnet ado.net > february 2007 >

dotnet ado.net : Data adapter.Update with fields that are part of the update condit


Roger Tranchez
2/27/2007 10:13:33 AM
Hello,

I'm trying to update some records of a database table called
"PETICIONS_TRESORERIA" with this structure:

codi int
data_peticio datetime
name varchar

(first two fields made the primary key)
..
..
..
I'm using a data adapter with a UpdateCommand as follows:

update PETICIONS_TRESORERIA set
codi=@codi,data_peticio=@data_peticio,name=@name where codi=@codi and
data_peticio=@data_peticio

The "SourceVersion" property for the UpdateCommand parameters @codi and
@data_peticio, are set to "DataRowVersion.Original", as if the user change
them on the associated datagrid , I want to return the original values for
changing them

An example will be more clear:

If I have these original values for codi, data_peticio and name :

1000,1/1/2007,Roger

And I change the "name" to other value, when I do the data adapter update,
it works perfect, but, if I change the code or data_peticio, nothing happens
(no errors, no update).

The same happens if I undo the definition of the primary key on the table.

What's the problem ?


Thanks in advance,


Roger Tranchez
RobinS
2/27/2007 12:15:15 PM
You are setting code to the original version in both cases. You need to use
different parameters, one for codi in the SET clause, and one for codi in
the WHERE clause. Same for data_peticio. The one in the WHERE clause
should be DataRowVersionOriginal, the other one needs to be
ModifiedCurrent.
Robin S.
---------------------------------------
[quoted text, click to view]

Roger Tranchez
2/27/2007 1:00:36 PM
Hi,

THIS IS an absolute satisfactory answer ! thanks a lot... nothing like being
a "crack" as you... thanks again.

p.d.: I love managed newsgroups 8-D ; I hope someday I could help others as
you so easily...

--
Roger Tranchez
..NET 2005 and DB developer


[quoted text, click to view]
RobinS
2/27/2007 3:31:33 PM
Thanks, you're very kind. Everybody knows *something* they can share. :-)

Robin S.
----------------------
[quoted text, click to view]

AddThis Social Bookmark Button