Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put into code to clear data in all table

Status
Not open for further replies.

eyeshield21

Programmer
Aug 13, 2014
62
PH
When I press a button, then all saved data on all tables
will be deleted or something like reset
tnx in advance...
 
Make all those changes in a huge transaction, and perform a "end transaction" to save the changes, respectively perform a "rollback", otherwise.

Looking the other way around, you can store the changes in some cursors, and only if you choose save, write them to the database.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
You can clear all the content of all the tables in a VFP database by opening the .dbc file, scanning the records and
opening each table in turn (exclusively) and zapping the contents.

That would work a little like this:

Code:
			USE ("myDatabase.DBC") ALIAS DATATABLE
			GO TOP
			DO WHILE .NOT. EOF()
				IF UPPER(OBJECTTYPE) = "TABLE"
					SELECT 0
					USE (DATATABLE.OBJECTNAME) EXCLUSIVE
					ZAP
					USE
				ENDIF
				SELECT DATATABLE
				SKIP
			ENDDO
			USE
			CLOSE ALL

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
It is not clear what you are trying to achieve.

Do you want to edit some data in the table, and then revert the data to the way it was before (in other words, get rid of the edits)?

If so, then Vilhelm-Ion has given you a good answer. But keep in mind that while the transaction is in force, all the data will be locked, so other users won't be able to access it, and this could seriously slow down the application in a multi-user environment.

Another approach would be to put the tables in a table-buffering mode, and then issue a TABLEREVERT() to revert the data. But you would have to do that with each table individually. Personally, I would go with a transaction in this case.

Or, do you want to clear out all the data from the tables. In that case, you can zap the tables, as suggested by Griff. And you can do that even if the tables aren't in a database. In that case, instead of looping through the tables indicated by the DBC, you can use ADIR() to get the table names into an array, or simply open each one explicitly and zap it.

If neither of the above scenarios is correct, please explain your question more clearly.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Then the code above will most likely work for you

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
yes...I want to clear all data in to my tables...

That's a rather drastic and unusual step, and requires exclusive access to the tables, but the command you're looking for is ZAP.
 
You can create a copy of the database structure with GENDBC.PRG, it's in HOME()+"TOOLS" and is not only faster then zapping a copy (becuase the copy can take much time), but also safer (you don't accidentally zap any table you don't want to).

The way it works is asking you for a DBC and creating a PRG you can execute to create an empty database.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top