gpt4 book ai didi

python - 如何在access数据库中创建小数字段?

转载 作者:太空宇宙 更新时间:2023-11-03 14:48:26 25 4
gpt4 key购买 nike

我使用下面的代码在accessdb中创建十进制列,但是当我执行代码时它返回字段定义错误

dbname = r'C:/Users/Dhana/Documents/NewDB.accdb'
accApp = Dispatch("Access.Application")
dbEngine = accApp.DBEngine
workspace = dbEngine.Workspaces(0)

dbLangGeneral = ';LANGID=0x0409;CP=1252;COUNTRY=0'
newdb = workspace.CreateDatabase(dbname, dbLangGeneral, 64)

newdb.Execute("""CREATE TABLE AAA (ID COUNTER, Field1 DECIMAL(10,3));""")

但是我可以通过 Access 数据库界面(GUI)创建小数字段。请帮我解决这个问题。

最佳答案

@Andre 是对的,问题是你不能在 DAO 中使用 DECIMAL 数据类型,你需要 ADO。

您可以使用以下内容:

dbname = r'C:/Users/Dhana/Documents/NewDB.accdb'
accApp = Dispatch("Access.Application")
dbEngine = accApp.DBEngine
workspace = dbEngine.Workspaces(0)

dbLangGeneral = ';LANGID=0x0409;CP=1252;COUNTRY=0'
newdb = workspace.CreateDatabase(dbname, dbLangGeneral, 64)
conn = accApp.CurrentProject.Connection
conn.Execute("CREATE TABLE AAA (ID COUNTER, Field1 DECIMAL(10,3));")

关于python - 如何在access数据库中创建小数字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46081206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com