Sunday, September 11, 2016

Re: pymssql

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 <johnf@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.
To post to this group, send email to django-users@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.

--
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-users@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/dd97d1b0-e8d6-51da-7056-67d9c6832cad%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.


--
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-users@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-y4gU%3Dsm1dkpai9CbKsFjTNGxLHuB%3DMzx_b54O8PYbi4iw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment