I am trying to create a table in my SQL Server CE database. I am receiving an error. I thought it was the ' in the name, but even running it with just the numbers I receive the same error. I did a print on the command and ran it over at: http://www.w3schools.com/sql/trysql.asp?filename=trysql_create_table and it worked fine. Can someone steer me into the right direction of what I am missing?
Here is the error:
There was an error parsing the query. [Token in line number = 1, Token line offset 13, Token in error 191019 ]
Here is the code:
public static void CreateDataTable(string dataBase, string tableName)
{
try
{
tableName = "John's License_191019";
var createUser = string.Format(@"CREATE TABLE [{0}] (
[Identifier] INT NOT NULL ,
[Id] INT NULL ,
[Name] NVARCHAR(255) NULL ,
[Zone] INT NULL ,
[Map] INT NULL ,
[State] NVARCHAR(255) NULL ,
[Type] NVARCHAR(255) NULL ,
[Faction] NVARCHAR(255) NULL ,
[X] FLOAT NULL ,
[Y] FLOAT NULL ,
[Z] FLOAT NULL ,
[Create_Date] DATETIME NULL ,
[Update_Date] DATETIME NULL ,
PRIMARY KEY ([Identifier]))", tableName);
using (var conn = new SqlCeConnection(SQLHelper.Connection(dataBase)))
{
conn.Open();
using (var cmd = new SqlCeCommand(createUser, conn))
{
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("ExecuteNonQuery: " + ex);
}
finally
{
cmd.Dispose();
}
}
conn.Close();
conn.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show("CreateDataTable: " + ex);
throw;
}
}
How the string prints:
CREATE TABLE [John's License_191019] ([Identifier] INT NOT NULL ,[Id] INT NULL ,[Name] NVARCHAR(255) NULL ,[Zone] INT NULL ,[Map] INT NULL ,[State] NVARCHAR(255) NULL ,[Type] NVARCHAR(255) NULL ,[Faction] NVARCHAR(255) NULL ,[X] FLOAT NULL ,[Y] FLOAT NULL ,[Z] FLOAT NULL ,[Create_Date] DATETIME NULL ,[Update_Date] DATETIME NULL ,PRIMARY KEY ([Identifier]))