Roel
Roel

Reputation: 764

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

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.

Upvotes: 3

Views: 10962

Answers (1)

John Woo
John Woo

Reputation: 263693

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));";

Upvotes: 9

Related Questions