-1
我檢索從MSSQL的最後一個ID,並試圖增加它,並與ID存儲呸名字。但我得到「屬性錯誤:Nonetype對象有沒有屬性‘ID’ 」 ..The代碼和錯誤放在這裏:Nonetype對象有沒有屬性「ID」
import Tkinter,tkFileDialog
import shutil
import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=PAVAN;DATABASE=video;Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute("SELECT TOP 1 id FROM files ORDER BY id DESC ")
while 1:
row = cursor.fetchone()
if not row:
break
print row.id
cnxn.close()
middle = Tkinter.Tk()
def withdraw():
dirname = tkFileDialog.askopenfilename(parent=middle,initialdir="H:/",title='Please
select a file')
a="H:python(test)\py_"+row.id+".mp4"
b=shutil.copyfile(dirname,a)
if b!="":
print "Successfully Copied"
else:
print "Could not be copied"
B = Tkinter.Button(middle, text ="UPLOAD", command = withdraw)
middle.geometry("450x300+100+100")
middle.configure(background="black")
B.pack()
middle.mainloop()
我得到的錯誤是:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\hp\Desktop\upload.py", line 20, in withdraw
a="H:python(test)\py_"+row.id+".mp4"
AttributeError: 'NoneType' object has no attribute 'id'