Problem creating dbf table using JET/OleDb

  • Thread starter Thread starter Derek Griffiths
  • Start date Start date
D

Derek Griffiths

Basically I'm just trying to get my program to make a simple table. Lucky
for me that I choose to start with the simple ones I suppose.

Here's the SQL command I am trying to run: "CREATE TABLE Groups.dbf (Name
char (25),Number char (4));"

Here's the exception it generates:

Unhandled Exception: System.Data.OleDb.OleDbException: Syntax error in
field definition.

That points to the line of code where I execute the create table statement.

The weird part is that should be a completely valid SQL statement (it
works on mySQL anyways). I'm not quite sure what I'm doing wrong here. If
I remove the number field and just use "Create table groups.dbf (name char
(25))" then it works. Unfortunately a table with one field isn't very
useful. I've tried playing around with the whitespace, but nothing makes
it happy.

Here's the code I'm using in C# in case anyone things that's the problem:

public void createTable(string folder)
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="+folder+";Extended Properties=dBASE IV;User ID=Admin;Password=");
con.Open();
OleDbCommand create = con.CreateCommand();
create.CommandText = "CREATE TABLE Groups.dbf (Name char (25),Number
char (4));";
create.ExecuteNonQuery(); //Exception points to this line
}

Any ideas?

Thanks,
Derek
 
I took off the semicolon and played with it for a while. I didn't change
anything, but now it works. I can even make my whole table.

create.CommandText = "CREATE TABLE Groups.dbf (Name char (25),Numb char
(4),Address char (30),City char (12),Province char (2),Postal char
(6),Path char (4))";
 
Derek,

Actually, you did change something. You changed Number to Numb. Number
is probably a reserved word, and needs special escaping if you want to use
it as a column name.

Hope this helps.
 
Back
Top