首页 > 解决方案 > pyodbc.ProgrammingError: ('无效的参数类型。param-index=1 param-type=StringVar', 'HY105')

问题描述

我正在尝试使用 Python 将一些数据插入 DB2。我有一个 GUI 表单(TKINTER)来从用户那里获取数据,所以在每个条目中我需要分配一个变量,所以这里有一个例子:

comment = StringVar()

comment_label = Label(text="Comment:", font=("Arial", 12))
comment_label.place(x=20, y=150)
comment_entry = Entry(textvariable=comment, width="110", font=("Arial", 12))
comment_entry.place(x=120, y=150)

但是当我尝试插入这个变量时,我得到了这个错误:

pyodbc.ProgrammingError: ('Invalid parameter type.  param-index=1 param-type=StringVar', 'HY105')

顺便说一句,这是插入代码:

registrar_intervencion_cursor = conn_db2.cursor()
registrar_intervencion_query = "INSERT INTO BIUMO220.TICKREGINTERVENCION(numerador, responsable, fecha, centro, tipo_intervencion, subtipo, comentario, ref_producto_final, df_producto_final, ref_componente, df_componente, util, df_util, tiempo_intervencion) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
registrar_intervencion_cursor.execute(registrar_intervencion_query, numerador, responsable, fecha_hoy, resultado_centro, resultado_intervencion, resultado_subtipo_intervencion, comentario, ref_producto_final, res, ref_componente, componente_row, util, util_row, tiempo_aprox_intervencion)
registrar_intervencion_cursor.commit()

是的,这是一个很大的表格,有很多变量。

标签: pythonsqlpython-3.xinsertdb2

解决方案


推荐阅读