Skip to main content
updated license initalization, added note on using LINQPad 2.x on 64-bit OS's and how to avoid "COM object that has been separated from its underlying RCW cannot be used" errors
Source Link
blah238
  • 35.9k
  • 8
  • 96
  • 200

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.BindActiveRuntime == null)
        ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.DesktopEngineOrDesktop);
    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);
}

Image http://img225.imageshack.us/img225/9339/9fd7791fc8304059a9766ff.pngLINQPad Screenshot

  • (The warning in the results box is just a warning, did not affect the result)

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.

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()
{
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
    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);
}

Image http://img225.imageshack.us/img225/9339/9fd7791fc8304059a9766ff.png

  • (The warning in the results box is just a warning, did not affect the result)

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

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.

added LINQPad example
Source Link
blah238
  • 35.9k
  • 8
  • 96
  • 200

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()
{
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
    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);
}

Image http://img225.imageshack.us/img225/9339/9fd7791fc8304059a9766ff.png

  • (The warning in the results box is just a warning, did not affect the result)

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

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

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()
{
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
    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);
}

Image http://img225.imageshack.us/img225/9339/9fd7791fc8304059a9766ff.png

  • (The warning in the results box is just a warning, did not affect the result)

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

Source Link
blah238
  • 35.9k
  • 8
  • 96
  • 200

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