pymssql

41 views
Skip to first unread message

sum abiut

unread,
Sep 8, 2016, 8:48:55 PM9/8/16
to django...@googlegroups.com
Hi,
i have used pymssql to connet to windows database but i want to be able iterate and  only print out some specific fields.

here is what i did

conn=pymssql.connect(server,username,password,database)
    cus=conn.cursor()
    cus.execute("SELECT * FROM glbud ")

    for row in cus:
           print(row)
this works perfect, but when i try to iterate through and only print out specific fields i got the error NameError: name 'budget_code' is not defined


for row in cus:
           print(row.budget_code)


NameError: name 'budget_code' is not defined

the column name is budget_code, in mssql server 2008


any idea what i am doing wrong? please advise

john

unread,
Sep 9, 2016, 10:37:03 AM9/9/16
to django...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y6FWUjFwKw0D-6-8%2BggS6BP7uTFkz_aU45452f2sCpCYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

sum abiut

unread,
Sep 11, 2016, 6:04:02 PM9/11/16
to django...@googlegroups.com
Thanks heaps for your comments, manage to get it work using the as_dict` parameter of the `cursor` object,

cus=conn.cursor(as_dict=True)
cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud")
for row in cus:
    print(row['budget_code'],row['budget_description'],row['rate_type'])



i am using django, and i prance it


cheers,





On Sat, Sep 10, 2016 at 1:36 AM, john <jo...@jfcomputer.com> wrote:

take a look at

http://pymssql.org/en/latest/pymssql_examples.html

Johnf


On 09/08/2016 05:48 PM, sum abiut wrote:
Hi,
i have used pymssql to connet to windows database but i want to be able iterate and  only print out some specific fields.

here is what i did

conn=pymssql.connect(server,username,password,database)
    cus=conn.cursor()
    cus.execute("SELECT * FROM glbud ")

    for row in cus:
           print(row)
this works perfect, but when i try to iterate through and only print out specific fields i got the error NameError: name 'budget_code' is not defined


for row in cus:
           print(row.budget_code)


NameError: name 'budget_code' is not defined

the column name is budget_code, in mssql server 2008


any idea what i am doing wrong? please advise
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages