2014-03-19 264 views
-1

我在运行时创建了一个MS Access数据库,并试图创建一个表。 下面的代码在运行时创建表时显示错误“CREATE TABLE语句中的语法错误”。CREATE TABLE语句中的语法错误

cmmd.CommandText = "CREATE TABLE tblContacts([SectionID] AUTOINCREMENT PRIMARY KEY,[ScetionName] Text(50), [CatID] Number(Integer), [Rate] Number(Double), [Prefix] Text(5), [Suffix] Text(5), [NextNumber] Number(Integer), [Inactive] Yes, [ModUserID] Number(Integer),[ModDate] Date)"; 
cmmd.ExecuteNonQuery(); 
+1

[通过学习基础知识( http://msdn.microsoft.com/en-us/library/ms971485.aspx) – Sadique

+0

看看这个问题:http://stackoverflow.com/questions/1388971/how-i-create-access-database- at-runtime-in-c – BudBrot

回答

1

Access数据库引擎会忽略字段类型声明,如Number(Integer)。假设你会从OLEDB连接执行该语句,使用这样的产品......

cmmd.CommandText = "CREATE TABLE tblContacts([SectionID] COUNTER PRIMARY KEY,[ScetionName] Text(50), [CatID] Long, [Rate] Double, [Prefix] Text(5), [Suffix] Text(5), [NextNumber] Number(Integer), [Inactive] YesNo, [ModUserID] Long,[ModDate] DateTime)"; 

你可以找到一个表在此包括有效的Access DDL字段类型声明:Field type reference - names and values for DDL, DAO, and ADOX

+0

谢谢@HansUp。它运作良好。请帮我做关系。 CatID应该来自分类表?如何将它与CatID字段关联到tblCategory? – Sanjeev4evr

+1

使用'REFERENCES'关键词。请参阅[这里](http://allenbrowne.com/func-DDL.html#CreateTableDDL)示例---查看*“创建预订表”*下的示例。如果遇到麻烦,请发布新问题。 – HansUp

相关问题