如何创建在C#中的MS Access表编程? [英] How do you create an MS Access table in C# programmatically?
本文介绍了如何创建在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]));
这篇关于如何创建在C#中的MS Access表编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文