Python Forum
Error Handling/No results from SQL Query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error Handling/No results from SQL Query
#7
obviously your SELECT statement does not return anything. And thus cursor.fetchone() returns None. As a result your previous code was raising an exception. Now it just continue.
try
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=?"
        conn=pyodbc.connect(connstring)
        cursor=conn.cursor()
        cursor.execute(SQLstr, problemid )
        row = cursor.fetchone()
        if row:
            messagebox.showinfo("Owner found", "The ADMIN for this problem ID is:  " + row[0])
        cursor.close()
        PROBIDENTRY.delete(0,END)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Error Handling/No results from SQL Query - by buran - Jul-18-2018, 12:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculating Average with Error Handling mikasa 5 279 1 hour ago
Last Post: snippsat
Star python exception handling handling .... with traceback mg24 3 1,315 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Help needed with a "for loop" + error handling tamiri 2 2,589 May-27-2022, 12:21 PM
Last Post: tamiri
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,243 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  pymysql: insert query throws error wardancer84 12 4,660 Jan-28-2022, 06:48 AM
Last Post: wardancer84
  Query Syntax Error hammer 2 1,643 Jan-03-2022, 02:30 PM
Last Post: hammer
  Handling Python Fatal Error richajain1785 7 6,001 Oct-14-2021, 01:34 PM
Last Post: Tails86
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,176 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error using mariadb select query with form in python? shams 2 2,040 Jul-29-2021, 12:30 PM
Last Post: shams
  Error Handling JarredAwesome 5 2,999 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020