Reputation: 277
string query = "Create table " + name +
" (Manpower_Name NVARCHAR(50), Instance INT, Start NVARCHAR(30), End NVARCHAR(30));";
I make of this connection string in C# for a SQL Server CE database (a .sdf
file). But I am getting an error, as follows:
There was an error parsing the query. [ Token line number = 1,Token line offset = 77,Token in error = End ]
Executed from the function:
public void create_proj_table(string name)
{
string query = "Create table " + name + " (Manpower_Name NVARCHAR(50), Instance INT, Start NVARCHAR(30), End NVARCHAR(30));";
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
SqlCeCommand cmd = new SqlCeCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}
Upvotes: 1
Views: 167
Reputation: 5119
END
is a reserved word in Sql.
string query = "Create table " + name + " (Manpower_Name NVARCHAR(50), Instance INT, Start NVARCHAR(30), End NVARCHAR(30));";
If you must use it - i.e., you don't want to change the name of the row - enclose it with '[]', like this:
string query = "Create table " + name + " (Manpower_Name NVARCHAR(50), Instance INT, Start NVARCHAR(30), [End] NVARCHAR(30));";
Upvotes: 1
Reputation: 216293
The word END is a reserved keyword in SQL CE. If you need to use it you should enclose in square brakets
string query = "Create table " + name + " (Manpower_Name NVARCHAR(50), " +
"Instance INT, Start NVARCHAR(30), [End] NVARCHAR(30));";
Upvotes: 1
Reputation: 754518
End
is a keyword that you cannot use in your own tables - use something like EndDate
instead.
Also: I would assume Start
and End
are dates - I would strongly urge you to use DATETIME
instad of NVARCHAR(30)
for storing those!
So I'd change the CREATE TBALE
statement to something like this:
string query = "CREATE TABLE " + name +
" (Manpower_Name NVARCHAR(50), Instance INT, StartDate DATETIME, EndDate DATETIME);";
and then your code should work just fine.
Upvotes: 2