如何实现物理删除表!

summern 2003-03-28 08:55:10
在一个数据控件中如何实现物理删除表!
...全文
170 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fishmans 2003-03-30
  • 打赏
  • 举报
回复
drop table 表名
就OK啦
qbilbo 2003-03-29
  • 打赏
  • 举报
回复
下面是个压缩数据库的函数:

'因为ADO2.0没有压缩数据库的功能,(ADO2.1能实现这个功能,但仅为了能压缩数据库而去打个补丁,好象不值得) 所以选用DAO来实现。
'压缩数据库的函数
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 = True

Exit Function

10:
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
Wang_xiaoni 2003-03-29
  • 打赏
  • 举报
回复
先DROP 然后再压缩
northwolves 2003-03-28
  • 打赏
  • 举报
回复
drop
qbilbo 2003-03-28
  • 打赏
  • 举报
回复
什么数据库啊?

如果ACCESS的,删除完后压缩一下。不过好象控件没有这个方法。
引用DAO后,可以用DBEngine.CompactDatabase 来实现。

下面是DAO中关于CompactDatabase的帮助。

DBEngine.CompactDatabase olddb, newdb, locale, options, password

The 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.

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧