updateRow Blows

300
2
12-06-2011 12:55 PM
WilliamIde
New Contributor II
I am trying to update a date field if it is NULL.  Everything works but updateRow

I am typing it because the code is not on this network

import arcpy
from arcpy import env

env.workspace = "d:/IdeProjects"

mypath = "d:/Ideprojects/Defworkspace/DefGDB.mdb"

gdb_tobe_moded = mypath +"/fdmag"

cur = arcpy.UpdateCursor(gdb_tobe_moded)

fields = arcpy.ListFields(gdb_tobe_moded)

for row in cur:
   for field in fields:
       if field.name == "REPORT_DATE":
           # Save the current report date
            svrpt = row.getValue(field.name)

        if field.name == "INCIDENT_DT":
            if row.getValue(field.name) == None:
                 print "value stays"
             else:
                 row.setValue(field.name,svrpt)
                 cur.updateRow(row)
del row
del cur



If I comment out the updateRow it works but nothing is changed.  If I leave it in it blows.
With
Traceback ...
File ID myfile
cur.updateRow(row)
File ...*** arcobbjects.py
in line 102, in updateRow

return convertArcObjectToPythonObject(self._arc_object.UpdateRow(*gp_fixargs(args)))
RuntimeError: ERROR 999999:  Error executing Function
Cannot open database ' '. It may be a database that you application recognizes, or it may be corrupt

Any Help?
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
It appears there may be something wrong with your geodatabase.  Was the geodatabase created with ArcGIS, or Microsoft Access?  Do you need to use an Access database, or would you be able to use a File Geodatabase? 

Try creating a File Geodatabase, and copy the data from the Access database to the File Geodatabase using ArcCatalog (right-click > copy, right-click > paste).  Then try executing your code.  Also, if you want to update only the NULL values, you will need to change your code slightly:

import arcpy
from arcpy import env

env.workspace = "d:/Ideprojects/Defworkspace/DefGDB.mdb"

cur = arcpy.UpdateCursor("fdmag")

fields = arcpy.ListFields("fdmag")

for row in cur:
    for field in fields:
        if field.name == "REPORT_DATE":
            # Save the current report date
            svrpt = row.getValue(field.name)

        if field.name == "INCIDENT_DT":
            if row.getValue(field.name) != None:
                print "value stays"
            else:
                row.setValue(field.name,svrpt)
                cur.updateRow(row)

del row
del cur
0 Kudos
WilliamIde
New Contributor II
yup that got it many thanks.

Urban
0 Kudos