检索MSAccess数据库列说明 [英] Retrieve MSAccess database column description
问题描述
我有一个MS Access 2002-2003数据库。我想知道是否可以通过编程方式检索列说明。我已经可以使用
I have an MS Access 2002-2003 database. I'd like to know if there's a way to programmatically retrieve the column descriptions. I can already obtain the column type, name, etc. using
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
DataTable schemaTable = reader.GetSchemaTable();
foreach (DataRow myField in schemaTable.Rows)
{
foreach (DataColumn myProperty in schemaTable.Columns)
{
// etc...
}
}
但我无权访问说明信息(您可以在MSAccess中使用设计视图时查看)。
but I don't have access to the "Description" information (which you can view when using "Design View" in MSAccess).
是否有一种简单的方法来获取描述信息?
Is there a simple way to get the "Description" information?
推荐答案
这就是我最后要做的事情:
Here's what I ended up doing:
string columnName = "myColumnName"
ADOX.Catalog cat = new ADOX.CatalogClass();
ADODB.Connection conn = new ADODB.Connection();
conn.Open(ConnectionString, null, null, 0);
cat.ActiveConnection = conn;
ADOX.Table mhs = cat.Tables["myTableName"];
columnDescription = mhs.Columns[columnName].Properties["Description"].Value.ToString();
conn.Close();
这很好用,但是我在寻找合适的程序集添加引用时遇到了一些麻烦。我必须添加对 adodb.dll (。Net附带)的引用。我还必须添加对 Microsoft ADO Ext的引用。 2.8 for DDL and Security (是ActiveX组件)(在Visual Studio中添加引用时可在COM选项卡中找到)。
This works great, except I had some trouble finding the right assemblies to add as references. I had to add a reference to adodb.dll (which comes with .Net). I also had to add a reference to Microsoft ADO Ext. 2.8 for DDL and Security which is an ActiveX component (found in the COM tab when adding references in Visual Studio).
代码段很棒,但是如果您省略参考信息,就会有人卡住;)
Code snippets are great, but if you omit reference information, some people get stuck ;)
这篇关于检索MSAccess数据库列说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!