arcobjects – Converting an Access Table into a Geodatabase Table Using ArcObjects

arcobjectscesri-geodatabasems access

I have inherited an ArcGIS application that creates a number of access database tables. I'd like to use ArcObjects to convert them to proper geodatabase tables, which I understand to mean simply adding on an ObjectID.

I found an example showing how to do this with Python but couldn't locate one for C#. Could someone point me in that direction, or explain to me what needs to be done?

Best Answer

To save yourself a bit of code you could use the geoprocessor and call DataManagementTools.CopyRows. See also: How to run a geoprocessing tool

e.g.:

// Create the geoprocessor. 
Geoprocessor GP = new Geoprocessor();

// Create the tool process object.
ESRI.ArcGIS.DataManagementTools.CopyRows copyrowsTool = new
    ESRI.ArcGIS.DataManagementTools.CopyRows();

// Set parameter values.
copyrowsTool.in_rows = @"D:\St_Johns\data.mdb\roads_table";
copyrowsTool.out_table = @"D:\St_Johns\data.gdb\roads_table";

// Execute the tool. 
GP.Execute(copyrowsTool, null);

As an aside, you can use LINQPad to quickly prototype programs that are more like snippets like this. e.g.:

void Main()
{
    if (ESRI.ArcGIS.RuntimeManager.ActiveRuntime == null)
        ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
    var gp = new Geoprocessor();
    var copyRowsTool = new CopyRows();
    copyRowsTool.in_rows = @"C:\GISData\Database1.mdb\Table1";
    copyRowsTool.out_table = @"C:\GISData\Database1.gdb\Table1";
    gp.Execute(copyRowsTool, null);
}

LINQPad Screenshot

Add the necessary references (remember to show GAC assemblies) and namespaces in the query properties in LINQPad and off you go!

Image http://img850.imageshack.us/img850/9576/5878c5bb83924c1b9ab7c92.png Image http://img194.imageshack.us/img194/4394/ca8934bca75f47748eb4840.png

Notes:

  • If you want to use the older version of LINQPad (2.x) that targets .NET 3.5, and you are on a 64-bit OS, you will want to grab the LINQPad for .NET Framework 3.5 - x86 version of LinqPAD from this page. This is because ArcGIS Desktop/Engine is 32-bit and some assemblies (specifically the ESRI.ArcGIS.Version assembly) won't work with the standard LINQPad 2.x executable's build target of AnyCPU on 64-bit OS's. LINQPad 4.x (which targets .NET 4.x) does not seem to have this issue.

  • Also be sure to set "Always use fresh application domains" under Edit-Preferences-Advanced to avoid "COM object that has been separated from its underlying RCW cannot be used" errors when running a query/program a second time.