David David - 1 month ago 9
Vb.net Question

Calling a subroutine as part of a SQL Transaction

My project is an orders application, where users can enter orders from different customers, using an

UltraGrid
to enter and edit data. When the Delete key is pressed on the keyboard, it prompts a
MsgBox
for the user to confirm they want to delete the selected row, and if so, it runs a
DELETE
query to delete that row from the database.

I also have a Save button to allow the user to save the order/changes made to the order. Ideally, I only want the row in the grid to delete temporarily as, if the user then doesn't save the order, the order line shouldn't be deleted permanently from the database.

If I put the
DELETE
query into a separate subroutine, can I then call this subroutine from my class that is saving it as part of the transaction?

This seems like it isn't going to work, as I'd not only need to call the query, but also somehow store the deleted row somewhere temporarily so that it knows which data to delete in the transaction, as well as a
Boolean
variable to tell it whether there is even any data to delete...

Are there any simpler ways of doing this? Would the above way even work?

Answer

Sorted it... Nothing actually complex required at all, just needed to change the code, as below:

Try
   Dim Dc As New OleDbCommand
   Dim rowcode As String = ""

         rowcode = dr.Item("Product_Code").Value

Changed to:

Try
   Dim Dc As New OleDbCommand
   Dim rowcode As String = ""

         rowcode = dr.Item("Product_Code", DataRowVersion.Original)
Comments