VB. NET code compression Database

Source: Internet
Author: User
When we add data to the database and delete it, the database will become very large after repeated attempts, so we need to compress it.
The following functions can be used to compress databases:

''' <Summary>
''' Compressing the database
''' </Summary>
''' <Remarks> </remarks>
Private sub compactdatabase (byval pfilepath as string)
Dim pfilename as string
Pfilename = getfilename (pfilepath)
'Check whether the database file exists
If Len (Dir (pfilepath) then
'Back Up If you need to back up
If MessageBox. Show ("backup? "," Test ", messageboxbuttons. yesno, messageboxicon. Question) = windows. Forms. dialogresult. yes then
Wsmanageglobalparam. g_managefilecontrol.savefiledialogfile.title = "select Save directory"
Wsmanageglobalparam. g_managefilecontrol.savefiledialogfile.filename = pfilename
Dim pfilter as string = getfileextname (pfilename)
Wsmanageglobalparam. g_managefilecontrol.savefiledialogfile.filter = "file (*." & pfilter & ") | *." & pfilter
Wsmanageglobalparam. g_managefilecontrol.savefiledialogfile.showdialog ()
Dim R as dialogresult = wsmanageglobalparam. g_managefilecontrol.savefiledialogfile.showdialog ()
If R = windows. Forms. dialogresult. Cancel then
Exit sub
End if
Filecopy (pfilepath, wsmanageglobalparam. g_managefilecontrol.savefiledialogfile.filename)
End if
Wsdataset. setnothing ()
Dim jro as jro. jetengine
Dim ptemppath as string = gettemppath ()
Jro = new jro. jetengine ()
Jro. compactdatabase (wsmanageglobalparam. g_connection & pfilepath, wsmanageglobalparam. g_connection & ptemppath & "\" & pfilename)
Kill (pfilepath)
Filecopy (ptemppath & "\" & pfilename, pfilepath)
Kill (ptemppath & "\" & pfilename)
End if

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.