Hello - I have what I would think should be a fairly simple problem, but I just cannot get it to work. The app I'm building is pretty straightforward. User opens the app, enters a value (a problem ID, called PROBLEMID) and clicks a button. The app checks a SQL table for that value and returns back a user name.
I have gotten it to work when the problem ID is FOUND in the database table, but when the id doesn't exist, I just get an error. Can you help set me straight? I can't get TRY to work, or any IF not or IF !=
Thank you in advance for any help.
Here's the entirety of my code (and yes, I know it's lousy and inefficient)
I have gotten it to work when the problem ID is FOUND in the database table, but when the id doesn't exist, I just get an error. Can you help set me straight? I can't get TRY to work, or any IF not or IF !=
Thank you in advance for any help.
Here's the entirety of my code (and yes, I know it's lousy and inefficient)
import tkinter as tk #python3.x
from tkinter import messagebox
#import Tkinter as tk #python2.x
from tkinter import *
import pyodbc
#Set Up App Window & defaults
root = tk.Tk()
root.option_add("*Font", "Verdana")
root.configure(background='black')
root.geometry('220x125') # Size WxH
root.title("SERV OWNER FINDER")
#create labels and entry boxes
PROBIDLABEL = Label(root, text="Enter Problem ID ", bg = "Black", fg = "gray")
PROBIDENTRY = Entry(root, bg="light yellow")
PROBIDLABEL.place(x=1,y=3)
PROBIDENTRY.place(x=1,y=30)
def close_window():
root.destroy()
def checktable():
problemid = "'" + PROBIDENTRY.get() + "'"
connstring = 'DRIVER={SQL Server};SERVER=OBDEVSQLAGL05;DATABASE=DCollection;UID=xxxx;PWD=yyyy'
SQLstr="select OWNER from GD_SERV_ADMIN where PROBLEMID = " + problemid
conn=pyodbc.connect(connstring)
cursor=conn.cursor()
cursor.execute(SQLstr)
row = cursor.fetchone()
messagebox.showinfo("Owner found", "The ADMIN for this problem ID is: " + row[0])
cursor.close()
PROBIDENTRY.delete(0,END)
#Create Buttons
SubmitButton = Button(root, text="Submit", width = 8, command=checktable)
QuitButton = Button(root, text="Quit",width = 8, command=close_window)
#Place Buttons on Window
QuitButton.place(x=5, y=70)
SubmitButton.place(x=120, y=70)
root.mainloop()
