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

跟風遠走 提交于 2019-12-12 15:24:01

问题


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). 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.

EDIT: Thanks, Remou, that did the trick. Below is a quick test in 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();

回答1:


Using an ADOX catalogue, you can look at the field property Description, in VBA:

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")


来源:https://stackoverflow.com/questions/4936901/how-can-i-retrieve-column-descriptions-from-an-access-database-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!