【问题标题】:how to create decimal field in access database?如何在access数据库中创建十进制字段?
【发布时间】:2017-09-06 17:32:19
【问题描述】:

我使用下面的代码在 accessdb 中创建十进制列,但是当我执行代码时它返回 field definition error

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));""")

但我可以通过访问数据库界面(GUI)创建十进制字段。请帮我解决这个问题。

【问题讨论】:

  • 来自allenbrowne.com/ser-49.html 的提示:[DECIMAL] 在 Access 查询界面或 DAO 中不可用。使用 ADO 执行 DDL 查询语句。(不是 100% 确定这是问题所在)
  • @Andre 非常感谢你

标签: python python-2.7 ms-access ms-access-2010 win32com


【解决方案1】:

@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));")

【讨论】:

  • 非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多