Select to view content in your preferred language

ValueError: Row: Invalid input value for setting - when inserting rows

1824
3
Jump to solution
11-01-2012 01:17 PM
DarinaTchountcheva
Frequent Contributor
Hello everybody,

Here is what I want to do:

   - select data from a SQL Server database, which is not SDE using pyodbc
   - insert the records returned by the select into a table in a geodatabase

I am getting the following error:

***********************************************
Traceback (most recent call last):
  File "E:\Workspace\Warehouse\PythonScripts\PerformSpatialJoins.py", line 80, in <module>
    arcpyRow.YCoord = row.YCoord
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__
    return setattr(self._arc_object, attr, ao)
ValueError: Row: Invalid input value for setting
***********************************************

I understand that it doesn't like the value of the XCoord, but I don't understand why it doesn't like it.
The data type of the XCoord in the SQL Server table is "numeric", and the data type of the XCoord in the geodatabase table is "double". I also tried float and long integer (the coordinates are integer values even if they are in a numeric field). I always get this error. If I don't insert the XCoord and YCoord attributes, the script works as expected.

Any idea is greatly appreciated!

Below is the python script:

# Import arcpy module import arcpy import pyodbc import os  # Set Geoprocessing environments arcpy.env.overwriteOutput = True  DatabaseConnectionString = "Driver={SQL Server Native Client 10.0};SERVER=myserver;DATABASE=mydatabase;Trusted_Connection=yes" LocationsForGISProcessing = "dbo.vw_myview"  ScratchGeodatabasePath = "E:\\Workspace\\Warehouse\\ScratchWorkspace\\Scratch.gdb" TempLocationsForGISProcessing = "LocationsForGISProcessing"   ##################################################################################### # Create ODBC connection    conn = pyodbc.connect(DatabaseConnectionString) cursor = conn.cursor()  print "Connected to database"  ################################################################################## # Insert the data into the geodatabase  TempTable = ScratchGeodatabasePath + "\\" + TempLocationsForGISProcessing      # Process: Delete Rows From Previous Load arcpy.DeleteRows_management(TempTable)  arcpyCursor = arcpy.InsertCursor(TempTable)  cursor.execute("SELECT * FROM " + LocationsForGISProcessing) rows = cursor.fetchall() for row in rows:     arcpyRow = arcpyCursor.newRow()         arcpyRow.Location_Key = row.Location_Key         arcpyRow.From_Date = row.From_Date     arcpyRow.XCoord = row.XCoord     arcpyRow.YCoord = row.YCoord     arcpyCursor.insertRow(arcpyRow)    # Delete the arcypy cursor del arcpyCursor   # Close the connection if (cursor is not None):     cursor.close()     del cursor     if (conn is not None):        conn.close()     del conn 
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Alum
Have you tried an explicit conversion from numeric type to float?  (I could be mistaken on this, but aren't Python "Double" types actually "Float"?).  Anyway, try something like this:

# convert the sqlserver type from numeric to float arcpyRow.XCoord = float(row.XCoord)



# or maybe attempt to use a variable if the above fails xval = float(row.XCoord) arcpyRow.XCoord = xval

View solution in original post

0 Kudos
3 Replies
JamesCrandall
MVP Alum
Have you tried an explicit conversion from numeric type to float?  (I could be mistaken on this, but aren't Python "Double" types actually "Float"?).  Anyway, try something like this:

# convert the sqlserver type from numeric to float arcpyRow.XCoord = float(row.XCoord)



# or maybe attempt to use a variable if the above fails xval = float(row.XCoord) arcpyRow.XCoord = xval
0 Kudos
DarinaTchountcheva
Frequent Contributor
James,

That did it!

Thank you so much!

Darina
0 Kudos
JamesCrandall
MVP Alum
James,

That did it!

Thank you so much!

Darina


Excellent!
0 Kudos