title: MS Access Oledb column properties
body: <p>And I solved this problem in VBA using DAO <a href="https://stackoverflow.com/questions/18367441/vba-access-getting-rowsource-to-find-lookup-values">here</a></p>
  
  <p>Using the Oledb framework, I created a function that can look up a record value. However it only gets the raw value. I need to find the value of the column property called "Row Source"</p>
  
  <p>Can someone explain to me how to find the foreign key value using Oledb</p>
  
  <p>Below is my function for a traditional look up query.</p>
  
  <pre><code>string IDatabase.LookupRecord(string column, string table, string lookupColumn, string lookUpValue)
  {
      OleDbCommand cmdLookupColumnValue = new OleDbCommand();
  
      string sqlQuery = "SELECT [" + table + "].[" + column + "] " +
                        "FROM [" + table + "] " +
                        "WHERE [" + table + "].[" + lookupColumn + "] = '" + lookUpValue + "'";
  
      cmdLookupColumnValue.CommandText = sqlQuery;
      cmdLookupColumnValue.CommandType = CommandType.Text;
      cmdLookupColumnValue.Connection = connection;
  
      string result = "";
  
      try
      {
          result = cmdLookupColumnValue.ExecuteScalar().ToString();
      }
      catch(Exception ex)
      {
          MessageBox.Show("Query is not valid :" + ex.ToString());
      }
  
      return result;
  }
  </code></pre>
  
  <p><strong>EDIT</strong> I found the following code <a href="https://stackoverflow.com/questions/7041824/retrieve-msaccess-database-column-description">here</a> Its the closest Ive gotten so far. It does get column properties like the column Description but it doesnt work for row Source. Any Ideas?</p>
  
  <pre><code>public void Test()
      {
          string columnName = "Main Space Category";
  
          ADOX.Catalog cat = new ADOX.Catalog();
          ADODB.Connection conn = new ADODB.Connection();
          conn.Open(connectionString, null, null, 0);
          cat.ActiveConnection = conn;
          ADOX.Table mhs = cat.Tables["FI - ROOM"];
  
          var columnDescription = mhs.Columns[columnName].Properties["Description"].Value.ToString();
  
          MessageBox.Show(columnDescription);
  
          conn.Close();               
      }
  </code></pre>