如何使用ADOX连接到现有的Access数据库 [英] How to use ADOX to connect to existing Access database

查看:481
本文介绍了如何使用ADOX连接到现有的Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个快速谷歌,我发现了如何使用ADOX来创建一个新的数据库和一些tabels和行添加到它。下面是一个例子:

From a quick google i found out how to use ADOX to create a new database and add some tabels and rows to it. Here is an example:

using ADOX;
...
ADOX.Catalog cat = new ADOX.Catalog();
cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=mydb.accdb;");
Table mainTable = new Table();
mainTable.Name = "Test Table";
mainTable.Columns.Append("Column_1");
cat.Tables.Append(mainTable);

这将创建一个新的数据库,并与新创建的数据库工作,但如果我有一个现有的数据库,我怎么会得到 ADOX.Catalog猫; 来连接到现有的数据库

This creates a new database and works with that newly created database but If I had an existing database, how would I get ADOX.Catalog cat; to connect to the existing database?

推荐答案

好吧,我理解了它。必须将ActiveConenction属性设置为ADODB.connection对象像在从 MSDN

OK, i figured it out. You have to set the ActiveConenction property to an ADODB.connection object like in the following example from msdn:

Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog

cnn.Open "Provider='Microsoft.Jet.OLEDB.4.0';" & _
    "Data Source= 'Northwind.mdb';"
Set cat.ActiveConnection = cnn
Debug.Print cat.Tables(0).Type

cnn.Close
Set cat = Nothing
Set cnn = Nothing

这篇关于如何使用ADOX连接到现有的Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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