编程管理(添加、删除、刷新) Access 链接表信息[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 playyuer 的 blog

'首先 , 作如下测试工作:
'新建空白 access 数据库 (.mdb) 文件,
'并添加若干类型链接表:
'dbase 5 (*.dbf)、
'microsoft excel (*.xls)、
'microsoft access (*.mdb;*.mda;*.mde) 等,
'然后再编写如下 vb6 程序:
'delphi、vc 等程序同理也可:
'引用 microsoft activex data objects 2.x library
'引用 microsoft ado ext. 2.x for ddl and security
'控件: form1、command1、command2、command3
private sub command1_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 adotable as new adox.table
set adotable.parentcatalog = adocatalog
dim i as integer
for each adotable in adocatalog.tables
    if adotable.type = "link" then
       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 if
next adotable
end sub
'编程添加链接表
private sub command2_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
dim adotable as new adox.table

'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 = "产品"
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

本文关键:Access,链接表,ADOX,VB
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top