Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me......i am newbie in python programming i want to create a treeview  i want to input a multiple item to a treeview before inserting it to mysql database.This is my code....when i inserted the data to mysql....it only allow 1 item inserted and that item is the last row i inserted even do it is multiple data.

What I have tried:

def Addmultipledata():

global data_list1, data_list2,record,data
global count



global count,

first1 = fn_entry1.get()
last1 = ln_entry1.get()
ID1 = ID_entry1.get()
Address1 = Address_entry1.get()
city1 = City_entry1.get()
Zipcode1 = Zipcode_entry1.get()


data_list= [ ]
data_list.clear()
data_list.append(first1)
data_list.append(last1)
data_list.append(ID1)
data_list.append(Address1)
data_list.append(city1)
data_list.append(Zipcode1)

data_list2 = []
data_list2.append(data_list)
data_list1=tuple(data_list1)

for x in data_list2:
    six_tree.insert(parent='', index='end',iid=count,text="", values=(x[0],x[1],x[2],x[3],x[4],x[5]))
    count = count + 1

fn_entry1.delete(0, END)
ln_entry1.delete(0, END)
ID_entry.delete(0, END)
Address_entry1.delete(0, END)
City_entry1.delete(0, END)
Zipcode_entry1.delete(0, END)

def multiplesql():

    mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    password="12345",
    database="SCHOOLREG"
)

my_cursor = mydb.cursor()
sql_command = """INSERT INTO Studentreg(First_Name,Last_Name,Student_id, Address,CITY,Zipcode) VALUES(%s,%s,%s,%s,%s,%s) """
# values = (record[0], record[1], record[3], record[4], record[5])
results = my_cursor.executemany(sql_command, data_list2)

mydb.commit()
Posted
Comments
Richard MacCutchan 7-Jul-22 10:32am    
What type of objects are the ones that have the get method, and where are they initialised? Why are you creating first1, last1 etc., rather than using the result of the get method to populate data_list? Why are you creating data_list2 and data_list1 (which looks like an error)? Where a re the actual values relating to your sql INSERT statement? Why are you calling executemany,for a single set of values?
Member 15696171 8-Jul-22 7:10am    
sir the get method come from the entry box .... the user should input 6 item to entry box..... then the item will insert to treeview data_list and data_list2 and data_list1 i want to create a list of tuple so that the mysql will read it before insert to mysql database ..... i try executemany because i want to have a set of list so the many item can insert to database same time....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900