如何在 C# 中从 Access 数据库检索列描述?
我正在尝试使用 C# 检索 MS Access 列的列描述(用户在表设计器中输入的用于描述列用途的文本)。如何解决这个问题呢?我想也许列中的 ExtendedProperties 会保留这个,但是当我通过 OleDbConnection 获取 DataTable 并循环遍历列时,ExtendProperties 的计数始终为 0。
编辑:谢谢,Remou,这成功了。下面是 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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ADOX 目录,您可以查看 VBA 中的字段属性“描述”:
Using an ADOX catalogue, you can look at the field property Description, in VBA: