´Access
Set adoCatalog.ActiveConnection = adoConnection
Set adoTable.ParentCatalog = adoCatalog
adoTable.Properties.Item("Jet OLEDB:Link Datasource").Value = "e:\nwind2kpwd.mdb"
adoTable.Properties.Item("Jet OLEDB:Remote Table Name").Value = "產(chǎn)品"
adoTable.Properties.Item("Jet OLEDB:Create Link").Value = True
adoTable.Properties.Item("Jet OLEDB:Link Provider String").Value = "MS Access;Pwd=456"
adoTable.Name = "Access"
adoCatalog.Tables.Append adoTable
adoConnection.Close
´dBase
adoConnection.Open
Set adoCatalog.ActiveConnection = adoConnection
Set adoTable.ParentCatalog = adoCatalog
adoTable.Properties.Item("Jet OLEDB:Link Datasource").Value = "E:\Borland\Shared\Data"
adoTable.Properties.Item("Jet OLEDB:Remote Table Name").Value = "animals#dbf"
adoTable.Properties.Item("Jet OLEDB:Create Link").Value = True
adoTable.Properties.Item("Jet OLEDB:Link Provider String").Value = "dBase 5.0"
adoTable.Name = "dBase5"
adoCatalog.Tables.Append adoTable
adoConnection.Close
´Excel
adoConnection.Open
Set adoCatalog.ActiveConnection = adoConnection
Set adoTable.ParentCatalog = adoCatalog
adoTable.Properties.Item("Jet OLEDB:Link Datasource").Value = "E:\Book97.xls"
adoTable.Properties.Item("Jet OLEDB:Remote Table Name").Value = "Sheet1$"
adoTable.Properties.Item("Jet OLEDB:Create Link").Value = True
adoTable.Properties.Item("Jet OLEDB:Link Provider String").Value = "Excel 5.0;HDR=NO;IMEX=2"
adoTable.Name = "Excel"
adoCatalog.Tables.Append adoTable
adoConnection.Close
´...
End Sub
´編程刪除鏈接表
Private Sub Command3_Click()
Dim adoConnection As New ADODB.Connection
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\LnkTbls.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
Dim j As Integer
Dim i As Integer
For i = adoCatalog.Tables.Count To 1 Step -1
If adoCatalog.Tables.Item(i - 1).Type = "LINK" Then
Debug.Print adoCatalog.Tables.Item(i - 1).Name
For j = 0 To adoCatalog.Tables.Item(i - 1).Properties.Count - 1
Debug.Print " " & adoCatalog.Tables.Item(i - 1).Properties.Item(j).Name & ": " & adoCatalog.Tables.Item(i - 1).Properties.Item(j).Value
Next j
Debug.Print VBA.vbCrLf
If VBA.MsgBox("Delete link table [" & adoCatalog.Tables.Item(i - 1).Name & "]?", vbYesNo) Then
adoCatalog.Tables.Delete adoCatalog.Tables.Item(i - 1).Name
End If
End If
Next i
End Sub
Private Sub Command4_Click()
Dim adoConnection As New ADODB.Connection
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\LnkTbls.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
adoCatalog.Tables.Item("Excel").Properties.Item("Jet OLEDB:Link Provider String").Value = "Excel 5.0;HDR=yes;IMEX=2"
End Sub
Private Sub Form_Load()
Command1.Caption = "鏈接表信息"
Command2.Caption = "添加鏈接表"
Command3.Caption = "刪除鏈接表"
Command4.Caption = "刷新鏈接表"
End Sub