Data adapter.Update with fields that are part of the update condit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
..NET 2005 and DB developer
 
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.
 
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...
 
Thanks, you're very kind. Everybody knows *something* they can share. :-)

Robin S.
----------------------
 
Back
Top