1

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 simple way to get the "Description" information?

Charlie Salts
  • 13,109
  • 7
  • 49
  • 78
  • Possible duplicate of [How can I retrieve column descriptions from an access database in C#?](http://stackoverflow.com/questions/4936901/how-can-i-retrieve-column-descriptions-from-an-access-database-in-c) – alk Jul 05 '16 at 11:22

2 Answers2

2

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

Charlie Salts
  • 13,109
  • 7
  • 49
  • 78
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")

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

Community
  • 1
  • 1
JSJ
  • 5,653
  • 3
  • 25
  • 32
  • I realise now that my question is a duplicate, although I'll add my own answer with some additional information. Thanks! – Charlie Salts Aug 12 '11 at 15:23