Click here to Skip to main content
11,636,778 members (77,381 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# dbase OleDb
0
down vote
favorite
I am trying to create a DBF table when i get this error "Syntax error in field definition." , however there is nothing wrong with syntax , and when I change a certain column name from level to levels it debug just fine! anybody have an idea ? here is the code:
 string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D://Temp;Extended Properties=dBase IV"; //MessageBox.Show(connectionString);

        OleDbConnection connection = new OleDbConnection(connectionString);
        connection.Open();
 

 
        /* ---------------------------  Filling The DBF Files ----------------------*/
        using (OleDbCommand cmd = connection.CreateCommand())
        {
 

            cmd.CommandText = @"CREATE TABLE clients(
                                                        nbrclient   int             ,   
                                                        level      varchar(1)      ,    
                                                        type        varchar(10)     ,
                                                        name        varchar(80)     ,   
                                                        name2       varchar(80)     ,   
                                                        fname       varchar(50)     ,   
                                                        vip         varchar(40)     ,
                                                        langue     varchar(3)      ,    
                                                        salutations varchar(30)     ,
                                                        gender      varchar(30)     ,
                                                        title       varchar(30)    
                                                        ) ";
cmd.ExecuteNonQuery();
 
      }
Posted 30-Apr-13 7:24am
SalouaK397
Comments
ryanb31 at 30-Apr-13 13:35pm
   
level is likely a keyword.
SalouaK at 30-Apr-13 13:38pm
   
Yes, you are right , i reaserched the reserved words for dbase, and level is one of them! do you have anyidea how to escape it?
ryanb31 at 30-Apr-13 14:30pm
   
I don't. I would recommend not using it. In Microsoft SQL you use square brackets around it, [level], but a better idea is to think of a different word.
richcb at 30-Apr-13 14:36pm
   
I agree with ryanb31, do not ever use keywords as variable names. They are already being used. You cannot call a variable "int" in C#. It is reserved as is "level" in SQL.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Level is a reserved word. I would recommend not using it. In Microsoft SQL you use square brackets around it, [level], but a better idea is to think of a different word.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Yes , ryanb31 you're absolutly right , Level is a reserved word and the best thing is t not use reservedword a think of a better nomenclature , but since a whole system use those same nomenclature I cannot change, at least not right now, The good News is I have find a work around, Use (`) before and after the reserved word so instead of level `Level` passed with no problem at all Be careful not to confuse (') with (`).
thank you all for your good word and advise
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 263
1 stibee 249
2 Sergey Alexandrovich Kryukov 229
3 Suvendu Shekhar Giri 225
4 OriginalGriff 183
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,493
2 Mika Wendelius 6,909
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100