Charlie Salts
Charlie Salts

Reputation: 13488

Retrieve MSAccess database column description

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?

Upvotes: 1

Views: 1948

Answers (2)

Charlie Salts
Charlie Salts

Reputation: 13488

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

Upvotes: 2

JSJ
JSJ

Reputation: 5691

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#?

Upvotes: 1

Related Questions