将SQL Server表链接到Access

时间:2014-04-22 15:09:21

标签: c# .net jet linked-tables

我在这里找到了代码:Update linked tables in MS Access Database with C# programatically这将重新链接一个表,但是你如何实际链接表并更改名称与SQL Server中的名称?

我已经开始使用一些相当粗略的代码了,但我对这些参数感到不知所措......

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

编辑 - Access 2003 - 我想将SQL服务器中的表链接到访问

编辑#2。编辑#2 我找到了这个网站:http://bytes.com/topic/visual-basic-net/answers/379904-create-linked-table 并在那里修改了代码,但是我收到了“无法建立连接”的错误。在我的服务器上?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案......

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);