VB.Net OleDbException“字段定义中的语法错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21136321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:26:50  来源:igfitidea点击:

VB.Net OleDbException "Syntax error in field definition"

sqlvb.net

提问by rusty595

I'm trying to create a table in an Access database through an OleDbCommand in VB.Net with the following SQL:

我正在尝试使用以下 SQL 通过 VB.Net 中的 OleDbCommand 在 Access 数据库中创建一个表:

CREATE TABLE InTemp (Month DATE, Description TEXT(255), Cost DOUBLE, Patron TEXT(255));

The code works fine in Access, but running it in VB.Net returns the OleDbException "Syntax error in field definition".

该代码在 Access 中运行良好,但在 VB.Net 中运行它会返回 OleDbException“字段定义中的语法错误”。

Full VB code:

完整的VB代码:

Dim con As New OleDb.OleDbConnection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " + DatabaseLocale
con.Open()
Dim createInTemp As New OleDb.OleDbCommand("CREATE TABLE InTemp (Month DATE, Description TEXT(255), Cost DOUBLE, Patron TEXT(255));", con)
createInTemp.ExecuteNonQuery()

I know there's no problem with the connection as it works elsewhere in my program.

我知道连接没有问题,因为它可以在我程序的其他地方工作。

Any help gladly appreciated!

任何帮助都非常感谢!

回答by James

I'd stab a guess at Month DATEbeing the problem here, Monthis a function in MS Access so there's a good chance it's clashing. Try changing your query to

我猜测Month DATE是这里的问题,Month是 MS Access 中的一个函数,所以它很有可能发生冲突。尝试将您的查询更改为

CREATE TABLE InTemp ([Month] DATE, [Description] TEXT(255), [Cost] DOUBLE, [Patron] TEXT(255))

Also, as far as I am aware DATEis a type specific to the app, not necessarily the data store. I would use the actual underyling type which is DATETIME(same could be said for TEXT).

此外,据我所知,DATE是特定于应用程序的类型,不一定是数据存储。我会使用实际的底层类型,它是DATETIME(对于 也可以这样说TEXT)。

See Microsoft Access Data Types.

请参阅Microsoft Access 数据类型