开发者

Retrieve MSAccess database column description

开发者 https://www.devze.com 2023-03-27 12:39 出处:网络
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

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

but I don't have access to the "Description" information (which you can view when using "Design View" in MSAccess).

Is there a simpl开发者_运维知识库e 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();

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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消