Insert Cursor fails to write results to table. The Search Cursor is returning the results, but errors when trying to insert into field.
# Insert Cursor for GDB table to GDB table
# Import modules, environment settings
import arcpy, traceback, string
arcpy.env.overwriteOutput = True
# Database connection variables on SPGISPROC1
OutFGDB = r"P:\batch\APO\District_overlay.gdb\pa_fp_dat1"
InFGDB = r"P:\batch\APO\District_overlay.gdb\pa_fp_rel1"
#Create cursor for input table items
InCursor = arcpy.SearchCursor(InFGDB)
# Create a variable that stores the value for column in a given row of the input table
for InRow in InCursor:
parcel = InRow.getValue('pafp_frq_PARCEL')
fp_zone1 = InRow.getValue('pafp_frq_ZONE2')
# Copy the stored value from the input table into the output table
gdbCursor = arcpy.InsertCursor(OutFGDB)
row = gdbCursor.newRow()
if fp_zone1:
fp_zone1 = fp_zone1.upper
#Fill out fields with variables from input table
row.pafp_frq_PARCEL = parcel
row.pafp_frq_ZONE2 = fp_zone1
#Insert new row into output file
gdbCursor.insertRow(row)
#Delete cursor and row objects to remove locks on the data
del row
del cursor
Error Message:
Traceback (most recent call last):
File "C:\Python27\ArcGISx6410.1\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\gisdata\Python\Insert_table_Cursor.py", line 28, in <module>
row.pafp_frq_PARCEL = parcel
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__
return setattr(self._arc_object, attr, ao)
RuntimeError: ERROR 999999: Error executing function.
InsertCursor
outside thefor
loop. Because you create theInsertCursor
within thefor
loop, you are actually creating multipleInsertCursor
's which may be creating locks on your dataset.