[GIS] How to access a table in a personal geodatabase using C#

arcgis-10.0arcgis-10.1cesri-geodatabase

I've a personal geodatabase which has some shape files included. To get a "complex" relation I've created a single table which will be have 1:1 or 1:N references which the different shape files (atm. 3).

Now I want to know how I can:

  1. access the table in the personal geodatabase,
  2. add new entries to this table,
  3. remove/modify existing entries

using C#. Does anybody done this before and can help me to solve this question?

Thanks a lot!

Best Answer

If you are working with personal geodatabase, this code should work for you. For other kind of workspace, to open the workspace, you need different type of workspace factory.

void DoTableProcessing(string workspacePath)
{
    IWorkspace workspace = OpenWorkspace(workspacePath);
    List<ITable> tables = GetTables(workspace);
    //Do process
}

List<ITable> GetTables(IWorkspace workspace)
{
    var enumDataset = workspace.Datasets[esriDatasetType.esriDTTable];
    var datasets = new List<ITable>();
    IDataset dataset;
    while ((dataset = enumDataset.Next()) != null)
        datasets.Add(dataset as ITable);
    return datasets;
}

IWorkspace OpenWorkspace(string workspacePath)
{
    IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
    return workspaceFactory.OpenFromFile(path, 0);
}

To do work with ITable you may see ITable interface. You can do search, select, modify, add rows through this interface.