C#/SQLCE CREATE TABLE programmatically (Auto increment + Primary key)

10,339

try enclosing key in a brackets

string command = @"CREATE TABLE CONNECTION(" +
                        "connection_id INTEGER IDENTITY(1,1) PRIMARY KEY, " +
                        "host NVARCHAR(255), port INT, [key] NVARCHAR(50), " +
                        "last_used NVARCHAR(15));";
Share:
10,339
Roel
Author by

Roel

Updated on June 05, 2022

Comments

  • Roel
    Roel almost 2 years

    I am trying to create a table in a SQL CE database programmatically. Currently, I am using the following query - though I am getting an error;

    string command = @"CREATE TABLE CONNECTION(" +
                      "connection_id INTEGER IDENTITY(1,1) PRIMARY KEY, " +
                      "host NVARCHAR(255), port INT, key NVARCHAR(50), " +
                      "last_used NVARCHAR(15));";
    

    The error I am getting is:

    There was an error parsing the query. [ Token line number = 1, Token line offset = 104, Token in error = key ]

    I can't seem to figure out what I am doing wrong. I am used to MySQL and the queries are slightly different.

  • Dan Bracuk
    Dan Bracuk about 11 years
    Alternatively, pick another name for the column or you'll have to do this forever.
  • John Woo
    John Woo about 11 years
    @DanBracuk I agree! to avoid future pain :D