Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server的Python脚本_Python_Sql Server - Fatal编程技术网

SQL Server的Python脚本

SQL Server的Python脚本,python,sql-server,Python,Sql Server,我正在尝试使用python脚本更新我的数据库。当我尝试运行脚本时,输出会在字段的实际值之前显示text:或其他数据类型。关于如何摆脱这个问题有什么建议吗 for r in range(1, sheet.nrows): EasementNumber = (unicode(sheet.cell(r, 0))) Grantor = str(unicode(sheet.cell(r, 1))) Book = str(unicode(sheet.cell(r,2))) Pa

我正在尝试使用python脚本更新我的数据库。当我尝试运行脚本时,输出会在字段的实际值之前显示
text:
或其他数据类型。关于如何摆脱这个问题有什么建议吗

for r in range(1, sheet.nrows):
    EasementNumber = (unicode(sheet.cell(r, 0)))
    Grantor = str(unicode(sheet.cell(r, 1)))
    Book = str(unicode(sheet.cell(r,2)))
    Page = str(unicode(sheet.cell(r,3)))
    Day = str(unicode(sheet.cell(r,4)))
    Month = str(unicode(sheet.cell(r,5)))
    Year = str(unicode(sheet.cell(r,6)))
    EasementType = str(sheet.cell(r,7))
    Origin = str(unicode(sheet.cell(r,8)))
    Descriptions = str(unicode(sheet.cell(r,9)))
    ProjectName = str(unicode(sheet.cell(r,10)))

    values = (EasementNumber, Grantor, Book, Page, Day, Month, Year, EasementType, Origin, Descriptions, ProjectName)

    cursor.execute(query, values)

cursor.close()

cursor.commit()

您正在将单元格对象转换为字符串,而不是使用
单元格的

您可以一次获取一行的所有值,而不是逐个读取单元格:

for row in range(1, sheet.nrows):
    values = sheet.row_values(row, 0, 11)
    cursor.execute(query, values)

没有代码,没有人会说,为什么你看到
文本:
添加了代码示例。谢谢!这很有帮助!