我正在编写一个使用 ADO.NET OLEDB 提供程序的应用程序。数据库是Access。大多数数据库交互是通过 DDL/DML SQL 查询。
我现在需要创建链接表,而仅使用 ADO.NET 似乎没有办法做到这一点。既不是简单的 DDL 查询,也不是试图直接操作 Access 系统表。
我试图避免使用 ADOX,在我的应用程序中有额外的引用/依赖。有谁知道解决这个问题的方法?非常感激。
这是我目前使用 ADOX 创建链接表的方式。
using ADOX;
public static void CreateLinkedTable(string sourceDB, string sourceTable, string targetDB, string targetTable)
{
Catalog cat = new Catalog();
cat.let_ActiveConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + targetDB);
Table table = new Table();
table.Name = targetTable;
table.let_ParentCatalog(cat);
table.Properties["Jet OLEDB:Create Link"].Value = true;
table.Properties["Jet OLEDB:Link Datasource"].Value = sourceDB;
table.Properties["Jet OLEDB:Remote Table Name"].Value = sourceTable;
cat.Tables.Append(table);
}