I am trying to insert a row in my User table (SQL Server Compact 3.5). This is my query (LastName, FirstName and UserPassword are NVARCHAR, IsActive is BIT):
INSERT INTO Users (LastName, FirstName, IsActive, UserPassword) VALUES ('J', 'R', 1, 'T')
I converted this to the following code block in C#:
string returnQuery = "INSERT INTO Users (LastName, FirstName, IsActive, UserPassword)"
+ "VALUES(" + "'" + "@LastName" + "', '" + "@FirstName" + "', @IsActive" + ",'" + "@UserPassword" + "'";
SqlCeCommand returnQueryCommand =
new SqlCeCommand(returnQuery, connection) { CommandType = CommandType.Text };
returnQueryCommand.Parameters.AddWithValue("@LastName", newUser.LastName);
returnQueryCommand.Parameters.AddWithValue("@FirstName", newUser.FirstName);
returnQueryCommand.Parameters.AddWithValue("@IsActive", newUser.IsActive);
returnQueryCommand.Parameters.AddWithValue("@UserPassword", newUser.UserPassword);
I get a parsing error when running my code. However, when I run the query straight through CompactView, the row gets inserted just fine.
I am executed the query in another method (I am returning SqlCeCommand from this method).
Thoughts?
missing close bracket after values