0

I have read the question "Retrieving Data from SQL Using pyodbc" and its answers. I am able to retrieve DB data using pyodbc:

for row in cursor.fetchall():
    print( row )

However I get only rows of data, in each row which looks like

A, B, C
D, E, F

I would like it like a dictionary where the title of each column is also indicated for example

studentName:A, studentAge:B, studentGrade: C
studentName:D, studentAge:E, studentGrade: F

and so on, how can I get a list of dictionaries?

garrettmurray
  • 3,338
  • 1
  • 25
  • 23
Ghost
  • 549
  • 8
  • 29
  • https://stackoverflow.com/questions/16519385/output-pyodbc-cursor-results-as-python-dictionary has a solution. – Deepstop Jul 29 '19 at 21:47
  • 1
    Possible duplicate of [Output pyodbc cursor results as python dictionary](https://stackoverflow.com/questions/16519385/output-pyodbc-cursor-results-as-python-dictionary) – Gord Thompson Jul 29 '19 at 22:05

1 Answers1

1

You could try something like the following to get the expected results:

for row in cursor.fetchall():
  print(row.studentName, row.studentAge, row.studentGrade)

Hope it helps.

Eric
  • 2,636
  • 21
  • 25