1

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

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".

Full VB code:

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!

0

1 Answer 1

5

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

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

Also, as far as I am aware DATE is 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).

See Microsoft Access Data Types.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! I thought it'd be something dumb like that :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.