-1

I'm reading from one database and outputting certain columns to another database. I use a data frame to store the data and then iterate through the frame to output the column i'm interested in.:

for i in range(0,len(myframe.index)):
    cursor_conn2.execute(SQL2_UPD_NEWEMP,myframe.loc[i,"LNAME_EMP"])

but I keep getting an error:

raise TypeError("Params must be in a list, tuple, or Row")

This is SQL2_UPD_NEWEMP:

SQL2_UPD_NEWEMP="INSERT INTO DBO.NEW_EMP_CAL(LNAME) VALUES(?)"      

there is data in the frame. 113 rows, and LNAME_EMP is a valid name, and every row contains data.

This should be quite simple, but I'm not seeing where the error is being made, and it makes me sad.

When I run this code I see all the data:

for i in range(0,len(myframe.index)):
    print(myframe.loc[i,"LNAME_EMP"])

Any help would be appreciated. Thanks!

C0ppert0p
  • 634
  • 2
  • 7
  • 23

1 Answers1

2

Currently, you are passing a scalar as parameter. But as error clearly mentions, your parameter must be an iterable such as tuple:

cursor_conn2.execute(SQL2_UPD_NEWEMP, (myframe.loc[i,"LNAME_EMP"],))

Or a list:

cursor_conn2.execute(SQL2_UPD_NEWEMP, [myframe.loc[i,"LNAME_EMP"]])
Parfait
  • 104,375
  • 17
  • 94
  • 125
  • 1
    That is a pandas error. And you need to pass separate values into parameters equal to the number of param placeholders, `?`. `cur.execute(sql, [myframe.loc[i,"LNAME_EMP"], myframe.loc[i,"MNAME"]])`. – Parfait Jan 22 '18 at 20:38
  • Somehow I deleted the comment that led to Parfait's response. Essentially I asked how it was possible to add columns to the sql insert statement. Parfaits response, was spot on. – C0ppert0p Jan 24 '18 at 02:18