1
votes

I need to print the row count of the cursor while using select query using python. But it always returns -1 even the select query returns some values.

Code I've tried:

    cursor = conn.cursor()
    cursor.execute(query)
    print(cursor.rowcount)

How to print the rowcount of the cursor?

2
have you tried len(cursor.fetchAll()) - Chandu
I'm using Sql server @Hari krishnan - ArockiaRaj
Yaa len is working @CSMaverick - ArockiaRaj

2 Answers

1
votes

The below code returns the lenth of the row.

  rows = cursor.fetchall()
  len(rows)
0
votes
len( cursor.fetchall()) 

this should do