I have a table in database, where one column contains first name and second name together (divided by space).
I am trying to load these data, split each row and save it again into the table. It is possible to do that a display that data, but when I try to save it back, I am getting
'NoneType' object has no attribute 'split'.
import sys, os, pyodbc
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=C:/Users/vlcek/Desktop/pokusdb.accdb;'
)
connection = pyodbc.connect(conn_str)
cursor = connection.cursor()
cursor2 = connection.cursor()
sql="Select whole_name from people"
cursor.execute(sql)
for change in cursor:
devided=change[0].split()
print(devided[0]+"--"+devided[1])
sql2="Insert into people (user_id, Name, Surname) values (27, ?,?)"
cursor2.execute(sql2,(devided[0],devided[1]))
connection.close()
Without those two lines if would work fine and I can show the data in console, so there is problem in those tow lines:
sql2="Insert into people (user_id, Name, Surname) values (27, ?,?)"
cursor2.execute(sql2,(devided[0],devided[1]))
I tried to create also two connection.cursor objects, but it doesn't work even when I worked just with
cursor = connection.cursor()
Thank you for your advice,
Vaclav