问题
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