I am trying to do a patch where you delete a selected item from a gallery and also from a datasource. And then update the column Total which is in a another table called PaymentVaucher. Tables are linked with LineItems.ItemID = PaymentVaucher.ID
BrowseGallery has a datasource of sql table LineItems, and form has a datasource of another sql table PaymentVaucher. Both are on one Screen.
The patch is happening on a delete button on OnSelect, in BrowseGallery2:

You can see an error "Invalid argument type." How to fix this? Maybe my whole patch is wrong?
If I only use: Remove('[dbo].[LineItems]', BrowseGallery2.Selected) . Then the line gets removed from gallery and datasource, but ofcourse the update for Total in table PaymentVaucher does not happen.
Here is how the whole thing looks for better understanding:
