如何从C#中访问数据库中检索列的说明? [英] How can I retrieve column descriptions from an access database in C#?
问题描述
我想检索使用C#(由用户在表设计器来描述一栏的目的输入的文本)的MS Access列列说明。如何去这件事吗?我想,也许在列ExtendedProperties将举行这个,但是当我穿过列一个OleDbConnection和循环得到一个DataTable,ExtendedProperties始终为0,计数
编辑:谢谢,Remou,这确实的伎俩。下面是在C#中快速测试
目录猫=新ADOX.CatalogClass();
ADODB.Connection康恩=新ADODB.Connection();
conn.Open(_connectionString,NULL,NULL,0);
cat.ActiveConnection =康恩;
ADOX.Table MHS = cat.Tables [MyTableName];
字符串测试= mhs.Columns [ColumnOfInterest]属性[说明] Value.ToString()。
使用ADOX目录,你可以实地考察一下属性说明,在VBA:
catDB.ActiveConnection =供应商= Microsoft.Jet.OLEDB.4.0; &安培; _
数据源=&放大器; CurrentProject.FullName
将TBL = catDB.Tables(新建)
将FLD = tbl.Columns(测试)
Debug.Print FLD。属性(说明)
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();
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")
这篇关于如何从C#中访问数据库中检索列的说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!