From 1c18cb01dd31f6b50bb1b14a1d49337955363f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartal=20L=C3=A6arsson?= Date: Mon, 16 Feb 2026 14:15:07 +0000 Subject: [PATCH] select with param --- select_param-tsql.py | 3 --- select_param_tsql.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) delete mode 100644 select_param-tsql.py create mode 100644 select_param_tsql.py diff --git a/select_param-tsql.py b/select_param-tsql.py deleted file mode 100644 index 31a6a57..0000000 --- a/select_param-tsql.py +++ /dev/null @@ -1,3 +0,0 @@ -import pyodbc - - diff --git a/select_param_tsql.py b/select_param_tsql.py new file mode 100644 index 0000000..c929ce1 --- /dev/null +++ b/select_param_tsql.py @@ -0,0 +1,35 @@ +import pyodbc + +try: + + connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes') + + cursor = connection.cursor() + + prmID = 5 + + cursor.execute("select * from tblCustomers where id = ?",prmID) + + print("[Query results...]") + while 1: + row = cursor.fetchone() + if not row: + break + print(row.id, row.code, row.firstName, row.lastName) + + cursor.close() + connection.close() + + +except pyodbc.Error as ex: + print() + print("exception: ", ex) + cursor.close() + connection.close() + print() + exit() + +print() + + +