简体   繁体   English

如何从C#中的访问数据库中检索列描述?

[英]How can I retrieve column descriptions from an access database in C#?

I am trying to retrieve column descriptions for MS Access columns using C# (the text entered by the user in the table designer to describe the purpose of a column). 我正在尝试使用C#(用户在表设计器中输入的文本来描述列的用途)检索MS Access列的列描述。 How does one go about this? 怎么会这样呢? I thought maybe ExtendedProperties in the Column would hold this but when I get a DataTable through an OleDbConnection and loop through the columns, ExtendedProperties always has a count of 0. 我认为Column中的ExtendedProperties可能会保留这个但是当我通过OleDbConnection获取DataTable并遍历列时,ExtendedProperties的计数总是为0。

EDIT: Thanks, Remou, that did the trick. 编辑:谢谢,Remou,这样做了。 Below is a quick test in C# 以下是C#中的快速测试

            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"];
            string test = mhs.Columns["ColumnOfInterest"].Properties["Description"].Value.ToString();

Using an ADOX catalogue, you can look at the field property Description, in VBA: 使用ADOX目录,您可以在VBA中查看字段属性Description:

catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.FullName

Set tbl = catDB.Tables("New")

Set fld = tbl.Columns("Test")
Debug.Print fld.Properties("Description")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM