Programming Management (Add, Delete, Refresh) Access Link Table Information

zhaozj2021-02-08  237

'First, make the following test work:' New blank Access database (.mdb) file, 'and add several types of link table:' DBASE 5 (* .dbf), 'Microsoft Excel (* .xls),' Microsoft Access (* .mdb; *. mda; *. mde), etc., then write the following VB6 program: 'Delphi, VC and other programs can also:' reference Microsoft ActiveX Data Objects 2.x library 'reference Microsoft ADO Ext. 2. x for DDL and Security 'control: Form1, Command1, Command2, Command3Private Sub Command1_Click ()' test link information table Dim adoConnection As New ADODB.ConnectionadoConnection.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.CatalogSet adoCatalog.ActiveConnection = adoConnectionDim adoTable As New ADOX.TableSet adoTable.ParentCatalog = adoCatalogDim i As IntegerFor Each adoTable In adoCatalog.Tables If adotable.type = "link" the debug.print adotable.name for i = 0 to adotable.properties.count - 1 debug.print "& adotable.properties.Item (i) .name &": "& adotable. Properties.Item (i) .value next I debug.print VBA.vbcrlf end ifnext adotablend sub 'programming Add LED table Private Sub Command2_Click () Dim adoConnection As New ADODB.ConnectionadoConnection.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.catalogdim adotable as new adox.table

'AccessSet adoCatalog.ActiveConnection = adoConnectionSet adoTable.ParentCatalog = adoCatalogadoTable.Properties.Item ( "Jet OLEDB: Link Datasource") Value = "e: /nwind2kpwd.mdb". AdoTable.Properties.Item ( "Jet OLEDB: Remote Table Name" ) .Value = "Product" adotable.properties.Item ("Jet OLEDB: CREATE LINK"). Value = trueadotable.properties.ITEM ("Jet Oledb: Link Provider String"). Value = "MS Access; PWD = 456" adoTable.Name = "Access" adoCatalog.Tables.Append adoTableadoConnection.Close'dBaseadoConnection.OpenSet adoCatalog.ActiveConnection = adoConnectionSet adoTable.ParentCatalog = adoCatalogadoTable.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 = trueadotable.properties.Item ("Jet OLEDB: LINK Provider String"). Value = "DBase 5.0" adotable.name = "dbase5" adocatalog.tables.Append adotableadoconnection.close

'ExceladoConnection.OpenSet adoCatalog.ActiveConnection = adoConnectionSet adoTable.ParentCatalog = adoCatalogadoTable.Properties.Item ( "Jet OLEDB: Link Datasource") Value =. "E: /Book97.xls" adoTable.Properties.Item ( "Jet OLEDB: Remote Table "). Value =" Sheet1 $ "adotable.properties.Item (" Jet OLEDB: CREATE LINK "). Value = trueadotable.properties.ITEM (" Jet OLEDB: LINK Provider string "). Value =" Excel 5.0; HDR = NO; IMEX = 2 "adoTable.Name =" Excel "adoCatalog.Tables.Append adoTableadoConnection.Close '... End Sub' programming delete a link table Private Sub Command3_Click () Dim adoConnection As New ADODB.ConnectionadoConnection.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.CatalogSet adoCatalog.ActiveConnection = adoConnectionDim j As IntegerDim i As IntegerFor i = adocatalog.tables.count to 1 step -1 if adocatalog.tables.item (i - 1) .type = "link" the 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 Ifnext IEND SUB

Private Sub Command4_Click () Dim adoConnection As New ADODB.ConnectionadoConnection.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.CatalogSet adoCatalog.ActiveConnection = adoConnectionadoCatalog.Tables.Item ( "Excel") Properties.Item ( "Jet OLEDB: Link Provider String").. Value = "Excel 5.0; HDR = yes; IMEX = 2" End Subprise Sub Form_Load () Command1.caption = "Link table information" command2.caption = "Add Link table" Command3.caption = "Delete Link table" Command4.caption = "Refresh Link Table" End Sub

转载请注明原文地址:https://www.9cbs.com/read-1102.html

New Post(0)