将SQL Server表链接到Access [英] Link SQL Server Table Into Access

查看:138
本文介绍了将SQL Server表链接到Access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找到了代码:更新链接使用C#以编程方式在MS Access数据库中创建表,这将重新链接表,但是实际上如何链接表并从SQL Server中的标题更改名称呢?

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

编辑-Access 2003-我想将表从SQL Server链接到access

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

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

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?

推荐答案

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

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

这篇关于将SQL Server表链接到Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆