2个回答
展开全部
'修改表名要引用.Microsoft ADO Ext. 2.X for DDL and Security
Private Sub Command1_Click()
Dim db As New ADODB.Connection
db.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & "data source=" & App.Path & "\database.mdb"
db.Open
RenameTableName db, "oldTableName", "newTableName"
End Sub
'RenameTableName的返回值-1表示出错.
' 0表示没有存在要修改的表.
'1 表示成功
Public Function RenameTableName(DatabseConnectionObject As ADODB.Connection, strOldName As String, strNewName As String) As Integer
On Error GoTo acd
Dim tbl As ADOX.Table, cat As New ADOX.Catalog
Set cat.ActiveConnection = DatabseConnectionObject '设置目录的链接
RenameTableName = 0
For Each tbl In cat.Tables
If LCase(tbl.Name) = LCase(strOldName) Then
tbl.Name = strNewName '重命名表的名称
RenameTableName = 1
End If
Next
Exit Function
acd:
RenameTableName = -1
End Function
Private Sub Command1_Click()
Dim db As New ADODB.Connection
db.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & "data source=" & App.Path & "\database.mdb"
db.Open
RenameTableName db, "oldTableName", "newTableName"
End Sub
'RenameTableName的返回值-1表示出错.
' 0表示没有存在要修改的表.
'1 表示成功
Public Function RenameTableName(DatabseConnectionObject As ADODB.Connection, strOldName As String, strNewName As String) As Integer
On Error GoTo acd
Dim tbl As ADOX.Table, cat As New ADOX.Catalog
Set cat.ActiveConnection = DatabseConnectionObject '设置目录的链接
RenameTableName = 0
For Each tbl In cat.Tables
If LCase(tbl.Name) = LCase(strOldName) Then
tbl.Name = strNewName '重命名表的名称
RenameTableName = 1
End If
Next
Exit Function
acd:
RenameTableName = -1
End Function
参考资料: http://topic.csdn.net/t/20060109/12/4505648.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询