Link SQL Server Table Into Access

那年仲夏 提交于 2019-12-11 12:20:09

问题


I found code here: Update linked tables in MS Access Database with C# programatically That will re-link a table, but how do you actually Link the table and change the name from what it is titled in SQL Server?

I have gotten some pretty rough code started, but am getting hung-up on the parameters...

Microsoft.Office.Interop.Access.Application docacc = new Microsoft.Office.Interop.Access.Application();
docacc.DoCmd.TransferDatabase(AcDataTransferType.acLink

EDIT -- Access 2003 - and I want to link the table from SQL server into access

EDIT # 2 I found this site: http://bytes.com/topic/visual-basic-net/answers/379904-create-linked-table And have adapted code there, but I get an error of 'unable to establish connection' on my server?


回答1:


I found a solution....

string path = "path to Access database";
DAO.Database dd;
DAO.DBEngine db = new DAO.DBEngine();
DAO.TableDef tdf - new DAO.TableDef();
dd.db.OpenDatabase(path);
tdf = dd.CreateTableDef();
tdf.Name = "Whatever you want the linked table to be named";
tdf.Connect = "ODBC;Driver=SQL Server;Server=<Server Name>;Database=<DB NAME>;Trusted_Connection=YES";
tdf.SourceTableName = "Whatever the SQL Server Table Name is";
dd.TableDefs.Append(tdf);


来源:https://stackoverflow.com/questions/23223413/link-sql-server-table-into-access

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