How to programatically refresh linked tables through VB.net?

微笑、不失礼 提交于 2020-01-05 06:25:48

问题


I have an Access frontend with a lot of tables linked through ODBC to a MySQL backend. I have a VB.net application that sometimes adds columns to the tables in the backend, and when that happens, I need to refresh the link to the table in the frontend from the VB.net app to show the new columns.

I'll consider just about any solution as long as it doesn't require restarting MySQL or Access, and will allow me to refresh only the links I need to refresh (which I know in advance) as there are hundreds of links and tables in the frontend.


回答1:


This should get you started:

Dim Con As New ADODB.Connection
Dim Cat As New ADOX.Catalog
Dim tbl As New ADOX.Table

Con.Open(m_sAccessDbPath)
Cat.ActiveConnection = Con

' Name the new Table and set its ParentCatalog property
' to the open Catalog to allow access to the Properties
' collection.
tbl.Name = m_sAccessDbTableName
tbl.ParentCatalog = Cat

' Set the properties to create the link.
tbl.Properties("Jet OLEDB:Create Link").Value = True
tbl.Properties("Jet OLEDB:Link Provider String").Value = RemoteDbPath
tbl.Properties("Jet OLEDB:Remote Table Name").Value = RemoteTableName

' Append the table to the Tables collection.
Cat.Tables.Append(tbl)

Source: http://bytes.com/topic/visual-basic-net/answers/370859-create-linked-table-access



来源:https://stackoverflow.com/questions/3251513/how-to-programatically-refresh-linked-tables-through-vb-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!