如何创建在C#中的MS Access表编程?

问题描述:

command.CommandText = "CREATE TABLE MyTable (" +
                "[Count] INT NOT NULL AUTO_INCREMENT PRIMARY KEY ," +
                "[TimeAndDate] TIMESTAMP NOT NULL ," +
                "[SerialNumber] VARCHAR( 14 ) NOT NULL ," +
                "[Result] BOOL NOT NULL ," +
                "UNIQUE ([TimeAndDate]))";

command.ExecuteNonQuery();

code以上标志语法错误的异常,你能不能帮我纠正查询字符串?谢谢你。

Code above flags syntax error exception, can you help me correct the query string? Thank you.

我建议粘贴生成的查询文本到Access查询;它会告诉你错误所在。

I'd suggest pasting the resulting query text into an Access query; it will tell you where the error is.

在我访问XP,粘贴产生的SQL AUTO_INCREMENT上了一个语法错误;它应该是自动增量(见 Access 2007中的SQL数据类型的),并可以指定为一个数据类型,而不是一个制约因素。 BOOL也给了一个错误=>使用BIT

On my Access XP, pasting the resulting SQL gave a syntax error on AUTO_INCREMENT; it should be AUTOINCREMENT (see Access 2007 SQL data types) and be specified as a data type, not a constraint. BOOL also gave an error => use BIT

这工作结果:

CREATE TABLE MyTable (
               [Count] AUTOINCREMENT NOT NULL PRIMARY KEY ,
               [TimeAndDate] TIMESTAMP NOT NULL ,
               [SerialNumber] VARCHAR( 14 ) NOT NULL ,
               [Result] BIT NOT NULL ,
               UNIQUE ([TimeAndDate]));