0

I am trying to insert some data into SQL database using a python script, but I am facing an error, I am not sure why. Here is what I am doing

create_query = """INSERT INTO bcmdb.bcmdbuser.Groups (ParentGroupID, ChildGroupID, DirectChild) 
                           VALUES (100, ?, 0) """
record = (id_s)
cursor.execute(create_query, record)
conn.commit()

I am using "pypyodbc" to connect to database and its working fine, the issue this code produce is

TypeError: Params must be in a list, tuple or Row.

In cursor.execute(create_query, record) line specifically.

Any idea will be really appreciated.

0

1 Answer 1

1

That's a problem with one-valued tuples in Python. They must have a trailing comma. Try like this:

create_query = """INSERT INTO bcmdb.bcmdbuser.Groups (ParentGroupID, ChildGroupID, DirectChild) 
                           VALUES (100, ?, 0) """
record = (id_s,)
cursor.execute(create_query, record)
conn.commit()
Sign up to request clarification or add additional context in comments.

1 Comment

wow this worked cant believe it was this trivial i feel really stupid right now, thanks so much for answering!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.