J
John Carret
I need users to be able to edit the database file created by my application in MS Access and I
need to ensure they will enter suitable data only to prevent possible future errors. That's why
I need to use ENUM typed columns. I don't know where the problem might be but I'm not able to
add them into an Access database table. When I try to create a table with columns using
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\somefolder\\file.mdb";
string SQLQuery = "CREATE TABLE tname (" +
"col_1 ENUM('opt1', 'opt2') WITH COMPRESSION NOT NULL, " +
"col_2 VARCHAR(38) WITH COMPRESSION NOT NULL, " +
// etc.
"col_nminusone VARCHAR(9) WITH COMPRESSION NOT NULL, " +
"col_n TEXT WITH COMPRESSION NULL)";
OleDbCommand SQLCmd = new OleDbCommand(SQLQuery, conn);
conn.Open()
SQLCmd.ExecuteNonQuery();
conn.Close();
I encounter a "Field definition syntax error". I'm sure the error is caused by the ENUM thing,
because everything is fine when I execute the query without this part of the query string.
That's why I tried to execute the query without the "WITH COMPRESSION" or "NOT NULL" or both set
for the col_1, but the result was the same as the first time.
Another thing I tried is the SET column type => the same exception error message again.
What am I doing wrong?
Along with this I'd be very grateful for some other suggestions:
- how to set the format of a BIT typed column to yes/no upon creation using SQL query (this
property could be found in MS Access on the Lookup tabpage in the table design mode); the column
looks like a DataGridViewCheckBoxColumn then
- how to set the Allow Zero Length to false upon creation using SQL query
Any help would be greatly appreciated.
With regards
John Carret
need to ensure they will enter suitable data only to prevent possible future errors. That's why
I need to use ENUM typed columns. I don't know where the problem might be but I'm not able to
add them into an Access database table. When I try to create a table with columns using
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\somefolder\\file.mdb";
string SQLQuery = "CREATE TABLE tname (" +
"col_1 ENUM('opt1', 'opt2') WITH COMPRESSION NOT NULL, " +
"col_2 VARCHAR(38) WITH COMPRESSION NOT NULL, " +
// etc.
"col_nminusone VARCHAR(9) WITH COMPRESSION NOT NULL, " +
"col_n TEXT WITH COMPRESSION NULL)";
OleDbCommand SQLCmd = new OleDbCommand(SQLQuery, conn);
conn.Open()
SQLCmd.ExecuteNonQuery();
conn.Close();
I encounter a "Field definition syntax error". I'm sure the error is caused by the ENUM thing,
because everything is fine when I execute the query without this part of the query string.
That's why I tried to execute the query without the "WITH COMPRESSION" or "NOT NULL" or both set
for the col_1, but the result was the same as the first time.
Another thing I tried is the SET column type => the same exception error message again.
What am I doing wrong?
Along with this I'd be very grateful for some other suggestions:
- how to set the format of a BIT typed column to yes/no upon creation using SQL query (this
property could be found in MS Access on the Lookup tabpage in the table design mode); the column
looks like a DataGridViewCheckBoxColumn then
- how to set the Allow Zero Length to false upon creation using SQL query
Any help would be greatly appreciated.
With regards
John Carret