473,471 Members | 4,629 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

update cursor to update csv data by loop iteration error

1 New Member
I was wondering if i could ask for some advise. I wrote a script for my workplace that imports CSV data from a template sheet (with data) to a DB table. I wrote it with a series of loops so that I wouldn't have to hardcode the headers names(43 header name). The template is used so that the headers do match exactly the table in the DB. I keep getting a run time error at the line execution the row.name, where name is a variable that varies in value as the loop iterates thought each header name. When I run it through the degugger the explicit name does not exist. Is there an alternate way of doing this so that I dont have to hardcode this into the code?
Thank you ,

Iris




Expand|Select|Wrap|Line Numbers
  1. import arcgisscripting
  2. gp = arcgisscripting.create(9.3)
  3. gp.toolbox = "management"
  4.  
  5.  
  6. # Define workspace for infile and data out put
  7. workspace =gp.GetParameterAsText(0)#define workspace
  8. inFile ='gp.GetParameterAsText(1)# shape out file
  9. dataOutPut =gp.GetParameterAsText(2)#in geochem file
  10. gp.workspace = workspace
  11.  
  12. # open file and read header line.
  13. openInFile = open(inFile)
  14. headerLine = openInFile.readline()
  15. #splits header line by comma
  16. valueList = headerLine.split(",")
  17.  
  18. #iterating through the headerlist and create a header list
  19. index = 0
  20. for value in valueList:
  21. #index header names
  22. header = valueList[index]
  23.  
  24.  
  25. #while values in the value list iterate through list 
  26. while index <= valueList.index(header):
  27. #read the rest of the data
  28. cValuesList = openInFile.readlines()
  29. #for data in the data list 
  30. for cValue in cValuesList:
  31. #split the datalist by comma
  32. gValue = cValue.split(",")
  33.  
  34. #iteralete throught the datalist 
  35. headerindex = 0
  36. #create an insert cursor
  37. rows = gp.insertCursor(dataOutPut)
  38. #for each data value in the datalist, create a new row
  39. for gcvalue in gValue :
  40. row = rows.NewRow()
  41. Name = str(valueList[headerindex])
  42. row.Name = gValue[headerindex] #( line 46, in <module> 
  43. #RuntimeError: ERROR 99999: Error executing function.
  44. rows.InsertRow(row)
  45.  
  46. headerindex += 1
  47.  
  48.  
  49. #add 1 to the counter 
  50. index += 1 
  51.  
  52. # Clean up the cursor
  53. #del rowInserter
  54. gp.getmessages()
Jul 12 '10 #1
2 1959
bvdet
2,851 Recognized Expert Moderator Specialist
@irislarin
Would you mind reposting your code with the correct indentation? It's difficult to follow as is.
Jul 13 '10 #2
dwblas
626 Recognized Expert Contributor
Add a print statement here and it should help.
Expand|Select|Wrap|Line Numbers
  1. #iterating through the headerlist and create a header list
  2. index = 0
  3. for value in valueList:
  4.     #index header names
  5.     header = valueList[index]
  6.     print index, header, value
  7.  
  8.     #while values in the value list iterate through list 
  9.     print index, valueList.index(header)
  10.     while index <= valueList.index(header):
  11.         ## wouldn't this always be equal since you just did this
  12.         ## which may mean that you going past the end of valueList
  13.         ## but it is difficult to tell without proper indentations
  14.         ##
  15.         ## use for index, value in enumerate(valueList):
  16.         ##         header = value ## doesn't it ?
Edit: You want to readlines once. Record[0] is the header. Split it into a list. Then read records[1] till the end. Split each record, and the record list should line up with the header list. i.e.
Expand|Select|Wrap|Line Numbers
  1. for index, header in enumerate(header_list):
  2.     print header, this_record_list[index]
Get a simple print statement coded first to make sure everything lines up and then code the rest of the program. Post back with that code if you want some more help.
Jul 13 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: S.Patten | last post by:
Hi, I have a problem with updating a datetime column, When I try to change the Column from VB I get "Incorrect syntax near '942'" returned from '942' is the unique key column value ...
4
by: carol | last post by:
I need to do something relatively simple… I need to update a table using a cursor. (I may have to create a stored procedure for doing this…) I need to declare an update cursor, fetch the...
2
by: Jason (Kusanagihk) | last post by:
To all, I am writing a C# application; I've a DataGrid to show and edit data; then I tried to update the updated data by calling ADO_Adapter.update (ADO_DataSet, "TableName"); But it pop up a...
2
by: Keith Kuwatani | last post by:
I am using the ODBC .net provider against a pervasive 2000i database. The Data Adapter successfully generates Table Mapping, Select Statement and Insert Statement. However, the Update and Delete...
4
by: Alex | last post by:
help. Deploying a .Net Application using ADO and MS Access (Jet 4.0) and MDAC 2.8. Get error: OleDbError .... Data type mismatch in criteria expression ... The application works fine in...
0
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New...
0
by: Tavalss | last post by:
Have developed ASP.Net app using VS2005. App uses Visual Foxpro database via VFPOLEB provider. When in VS2005 development mode I can 'Insert' rows into database tables with no problem. I...
4
by: vanithapraveen | last post by:
I gave update command inside for loop.. and the query values are perfectly correct..but when i give con.execute(updateqry) i end up with an error.... Please help me...
1
by: vituko | last post by:
plpgsql (postgresql 8.3 but I can upgrade) I can open a cursor with a dynamic query (table / column variable) : -open cursor for execute '...' ; But if I want do updates... - execute 'update...
4
by: shalskedar | last post by:
I want to transfer the excel data to th Db ..thru the VBA code. In the DB there is a table called outer2 containing 1 of the columns as "Upvc" whose format is set to Long integer. When i try to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.