在一个数据控件中如何实现物理删除表!
解决方案 »
- (求思路)关于VB6播放wav文件的问题,请高手帮忙!!!!!!!!!!!!!!(帮忙就有分哦:))
- BASIC语言(不是VB,是最古老的BASIC)如何在WIN98中运行???
- listview的焦点移除问题。
- 问:在VB6.0企业版中,TRIM()和FORMAT()函数为什么不好用?
- 问题????!!!!!!
- 开心,送分给第一个回贴的人
- 请问各位VB怎样实现文件的复制和删除?
- 在ACCESS中怎么定义一个全局变量,如从一个窗口到另一个窗口传一个参数1
- 关于vb作数据库数据显示的问题!!(后台是用的oracle)
- 用vb如何编写与unix通讯的程序?
- 一个与编程无关的问题:“游戏人生”翻译成英文是什么?
- 请问如何使用winsock实现服务器的多线程监听
引用DAO后,可以用DBEngine.CompactDatabase 来实现。下面是DAO中关于CompactDatabase的帮助。DBEngine.CompactDatabase olddb, newdb, locale, options, passwordThe CompactDatabase method syntax has these parts.Part Description
olddb A String that identifies an existing, closed database. It can be a full path and file name, such as "C:\db1.mdb". If the file name has an extension, you must specify it. If your network supports it, you can also specify a network path, such as "\\server1\share1\dir1\db1.mdb".
newdb A String that is the file name (and path) of the compacted database that you're creating. You can also specify a network path. You can't use the newdb argument to specify the same database file as olddb.
locale Optional. A Variant that is a string expression that specifies a collating order for creating newdb, as specified in Settings. If you omit this argument, the locale of newdb is the same as olddb.
You can also create a password for newdb by concatenating the password string (starting with ";pwd=") with a constant in the locale argument, like this:
dbLangSpanish & ";pwd=NewPassword"
If you want to use the same locale as olddb (the default value), but specify a new password, simply enter a password string for locale:
";pwd=NewPassword"
options Optional. A constant or combination of constants that indicates one or more options, as specified in Settings. You can combine options by summing the corresponding constants.
password Optional. A Variant that is a string expression containing a password, if the database is password protected. The string ";pwd=" must precede the actual password. If you include a password setting in locale, this setting is ignored.
'压缩数据库的函数
Public Function CompactMdbFile(DbFile As String, Optional PassWord As String) As Boolean
Dim TempFile As String, i As Integer'------------------------- 获取临时文件名 ---------------------------------
Do
TempFile = "c:\temp" + Trim(Str(i)) + ".mdb"
i = i + 1
Loop Until Dir(TempFile, vbHidden) = ""'------------------------- 压缩数据库 ------------------------------------
On Error GoTo 10
If PassWord = "" Then
DBEngine.CompactDatabase DbFile, TempFile
Else
DBEngine.CompactDatabase DbFile, TempFile, , , ";pwd=" + PassWord
End If'------------------------ 删除源文件,用压缩后的文件代替原文件 ------------
'其实ACCESS中的压缩数据库也是通过这种方式来实现的。
Kill DbFile
Name TempFile As DbFile'------------------------ 返回 -------------------------------------------
CompactMdbFile = TrueExit Function10:
CompactMdbFile = False
End Function调用:
Dim Db As Database
'----------------- 从数据库中删除表 ----------------------------------------------
'打开数据库
Set Db = DBEngine.OpenDatabase("c:\export.mdb", False, False, "ms access;pwd=1234567")
'删除表
Db.TableDefs.Delete "data"
'关闭数据库
Db.Close'---------------- 压缩数据库 ----------------------------------------------------------
If CompactMdbFile("c:\export.mdb", "1234567") = False Then
MsgBox "Export.mdb 正在被其它程序打开,无法彻底删除该数据中的内容!", vbCritical
End If
就OK啦