我是python的初学者。我正在查询访问数据库。我打算将一个字符串变量传递给 sql 语句,但无法计算出双精度。
这是我的代码:
qllname = 29221.0
llname = "01-01-05-W2"
sqlstatement = recordset.Open("SELECT * FROM LLD WHERE LLD = '%s'" % (llname),connection,1,3)
for x in range(recordset.Fields.Count):
fields_dict[x] = recordset.Fields.Item(x).Name
print fields_dict[x], recordset.Fields.Item(x).Value, x
sqlstatement2 = recordset2.Open("SELECT * FROM SWAWELLS WHERE WWDR_NO = '%d'" % (qllname),connection2,1,3)
for x2 in range(recordset2.Fields.Count):
print recordset2.Fields.Item(x2).Value, type(recordset2.Fields.Item(x2).Value)
结果:
LLD 01-01-05-W2 0
X 678817.81875 1
Y 5431052.45982 2
Traceback (most recent call last):
File "L:/temporary/start of test/accessnew--.py", line 25, in <module>
sqlstatement2 = recordset2.Open("SELECT * FROM SWAWELLS WHERE WWDR_NO = '%d'" % (qllname),connection2,1,3)
File "<COMObject ADODB.Recordset>", line 4, in Open
com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft JET Database Engine', u'Data type mismatch in criteria expression.', None, 5003071, -2147217913), None)
>>>