problems with getting data into database

5,183 views
Skip to first unread message

Jannis Syntychakis

unread,
May 31, 2010, 9:22:24 AM5/31/10
to pyodbc
hallo everybody,

I am using Python 2.6, SQL, Pyodbc.
i want to write data into the database, but i can't.

thats what i'm doing:

cnxn = pyodbc.connect('DRIVER={SQL Server};
SERVER=VIRTUALXP-41099\SQLEXPRESS; DATABASE=qcEcho')
cursor = cnxn.cursor()
cursor.execute("insert INTO tabel1
values(2,2)",'column1','column2')
cnxn.commit()

zo what i want is to write values (2,2) in colums: column1 and columd2
in tabel1 of database qcEcho,

anyone knows what i am doing wrong?

thanks in advance!

jannis

ps.

pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 2
parameters were supplied', 'HY000')
>>>

John Hampton

unread,
May 31, 2010, 2:58:48 PM5/31/10
to pyo...@googlegroups.com
On 5/31/10 6:22 AM, Jannis Syntychakis wrote:
> cnxn = pyodbc.connect('DRIVER={SQL Server};
> SERVER=VIRTUALXP-41099\SQLEXPRESS; DATABASE=qcEcho')
> cursor = cnxn.cursor()
> cursor.execute("insert INTO tabel1
> values(2,2)",'column1','column2')
> cnxn.commit()

What the DBAPI thinks you want is to substitute the values "column1" and
"column2" into the query. However, you don't have any substitutions
defined in your query.

What you really want is something more like:

SQL = "insert into table1 (column1, column2) values (?, ?)"
cursor.execute(SQL, 2, 2)

Note, this is untested code.

-John

Jannis Syntychakis

unread,
Jun 1, 2010, 4:52:24 AM6/1/10
to pyodbc
it's working now! thanks! i had 2 () to much! thanks!
Message has been deleted

vamsi.sa...@gmail.com

unread,
Aug 17, 2016, 2:27:55 PM8/17/16
to pyodbc
how do we use the same in case of update? 

I used this, but it doesn't work

cur.execute ("update table set columnName= %s where ID = %s ",("test3","3"))
cur.commit()

vamsi.sa...@gmail.com

unread,
Aug 17, 2016, 2:30:29 PM8/17/16
to pyodbc
Wow I found the answer finally.


 cur.execute ("update tablename set columnName = (?) where ID = (?) ",("test4","4"))

Michael Kleehammer

unread,
Jan 19, 2017, 5:51:00 PM1/19/17
to pyodbc
That works, but you don't need the parens around the markers and you also don't need to put the parameters into a tuple.  The DBAPI specifies parameters be that way, but pyodbc supports both formats:

cur.execute("update tablename set columnName =? where id=?", "test4", "4")

yangl...@gmail.com

unread,
Jul 14, 2020, 5:39:24 PM7/14/20
to pyodbc
Do you know who would executemany() would work?
Reply all
Reply to author
Forward
0 new messages