David David - 1 year ago 64
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

to enter and edit data. When the Delete key is pressed on the keyboard, it prompts a
for the user to confirm they want to delete the selected row, and if so, it runs a
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
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
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 Source

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

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

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

Changed to:

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

         rowcode = dr.Item("Product_Code", DataRowVersion.Original)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download