That question is really generic, so i'll try to answer in a generic way.

As you can expect, the answer is 'That depends on what the click does'

If the button click adds one to a counter, the undo can subtract one from the same counter. In this case, once undone, the undo option should be disabled.

If the button click deletes a file, then the undo must recreate the file and fill it with the original content.

In general, in order to be able to do an undo, you need to persist the current status, before doing the action by the click, in order to be able to restore it from the result, if an undo is required. When the undo is done, then you must 'destroy' the containter that holded the status, because you cannot use it to 'repeat' the undo.

You will be aware that if more tan one undo is required, then you'll need to persist the status several times, being able to know the exact order of creation.

If you have many 'click evente' to catch, in my opinión, the best solution is to create an ordered list of events catched, including info about the order of caching, the 'title' of what you cached, and the location of the persisted info.

The undo action, will allways be done from newest to older. So, you need to get the highest order value in the list and retrieve this info, get the persisted info, and act according, and remove this entry from the list.

i have multiple buttons and text boxes that recieve's its corresponding button

Maybe you'll need a table (lets name persistInfo) having 2 string fields: variableName and value.
Then an structure (lets call it undoStatus) is needed to

Identify the order of each click

Identify the event cached

Identify the old status persisted temp file having the variables modified by the click, and their values before the click has been done.

With this structure, you 'should' declare an static List<undoStatus> and fill it with a new undoStatus each time you handle a click event (or whatelse event you want to catch for undo).

When you'll catch an event, you'll need to:

Create a new persistInfo table in a new Dataset

Fill it with the relevant variable names and their old values

Save the dataset with a unique name (IE using the DateTime.Now with a mask of yyyyMMddhhmmssffffff)

Get the new order for the structure: can be obtained using the Linq Max function againt the list and adding one to the obtained value, or setting a 0 value if nothing is in the list. Remember this value in a static variable.

'This tells each button to use the same handler for the click event
For Each SQLButton As Button In Me.Controls.OfType(Of Button)()
AddHandler SQLButton.Click, AddressOf Button_Click
Next

If there are other buttons, name the buttons for the database in a unique way,"SQL1, SQL2, etc", perhaps. then use For Each SQLButton As Button In Me.Controls.Find("SQL", True).OfType(Of Button)()

in the form class add this sub

'With this code you can identify the button that is clicked. From here you can pass the Name, or Text, or even the Button, whatever works for you, to the sub handling the connection and query to your database.
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim TempButton As Button = DirectCast(sender, Button)
End Sub

You said you wanted to run an SQL command for each button. My code was to give you a start, to show you how to use one set of code to handle every button. I also showed you how to use the code for only certain buttons.

in order to undo this action, you need to do one (or many) UPDATE sentence to restore the values before you did the UPDATE.

How you can handle that?

Before doing your "UPDATE fieldname='" & variablename & "' FROM database.tabename WHERE date='" & storeddate & "';" you will need to create a command like

"SELECT TOP 100 PERCENT * FROMdatabase.tabenameWHEREdate='" & storeddate & "';"
Whith this command, yu'll need to create a data adapter to retrieve the info from the DB and fill a new Dataset (using the data adapter) with a table having the result of this select. Remember that your table must contain a field that identifies each row.

This way you'll have the values before doing the update. But this is not enough.

Also you need to save this info in a file using the Dataset save method, and store the info about the button pressed, the table affected, the key field and the name of the file containing the Dataset Info, in order to have all the elements to restore the table to the previuos state before the update.

On the first step, please change your button click events to manage this.

You said you wanted to run an SQL command for each button. My code was to give you a start, to show you how to use one set of code to handle every button. I also showed you how to use the code for only certain buttons.

You didn't follow the code I gave you.
When you set the handles option on an event handler it will only handle the one object, unless you include other objects in the statement, Handles Button1.Click, Button2.Click, etc.. When you have alot of objects it's easier to add the handler to each one like my code showed you. When you do it this way you can't use the handles option.

Hi to Everyone,
I want to get the total (column) amount using Listview w/o database VB.NET
Help me please...
Thanks..
_______________________________________________________________________________________________________
lstitems
Item Name | …

I want to perform an UPDATE query but i'm getting this error: ![errorHAVING](/attachments/fetch/L2ltYWdlcy9hdHRhY2htZW50cy8zL2Vycm9ySEFWSU5HLkpQRw%3D%3D/500 "errorHAVING")
This is my Sub in vb.net:
Public Sub changeStatus()
Dim Sqlstr …

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...