[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Use DELETE + INSERT for UPDATE

Steven Spits

9/12/2002 3:01:00 PM

Hi,

The DB we're using for our .NET application doesn't support the UPDATE
statement when the key column was changed. We need to call a DELETE
statement first, followed by an INSERT statement.

In PowerBuilder, it was possible to specify this, so we didn't have to worry
about it.

Is there something like this in ADO.NET ?

Steven

- - -



1 Answer

(Hussein Abuthuraya(MSFT))

9/13/2002 3:01:00 AM

0

Steven,

The Update Statement needs the value of the KeyColumn in order to locate the row that need to be updated. So if this value is changed to something that doesn't exist in the
table, then it will not be able to locate that row.

In ADO.NET, we are dealing with completely disconnected data so we could do what we want on the client but when it's time to send the updates then the above is needed to
complete the operation.

You could implement something like what PowerBuilder is doing if you write some code that checks for the key column value and then builds a batch of SQL statements that
does Delete then Insert. In this case you will not be able to use the DataAdapter.Update because the RowState will be "Modified" and it is going to try and execute the
Update command. What you could do is execute the new Delete command using the ExecuteNonQuery command and then do the same for the Insert.

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....