问题
While trying to insert data to my SQl db i get the following error System.Data.SqlServerCe.SqlCeException: There was an error parsing the query. [ Token line number = 1,Token line offset = 52,Token in error = ) ]
my lines of code to enter the data are the following:
@{
var db= Database.Open("Games");
var sqlQ = "SELECT * FROM Games";
var data = db.Query(sqlQ);
}
@{
if (IsPost) {
var fileData = Request.Files[0];
var fileName = Path.GetFileName(fileData.FileName);
var fileSavePath = Server.MapPath("~/upload/" + fileName);
fileData.SaveAs(fileSavePath);
var GameName=Request["Name"];
var Gamefile = fileName;
var SQLINSERT = "INSERT INTO Games (Name, file_path) " + "VALUES (@0, @1,)";
db.Execute(SQLINSERT, GameName, Gamefile);
}
}
I am trying to upload a file to my server and add the filename to my database. The error is apparently with line 15.
回答1:
Trailing comma is my guess. change sql insert statement to this:
var SQLINSERT = "INSERT INTO Games (Name, file_path) " + "VALUES (@0, @1)";
回答2:
The problem in my case was in the middle of the sentence have the ' character
example (ERROR)
INSERT INTO Article (ARV_ARTICLE, ARV_NAME, ARV_BRAND_ID, ARV_GROUP)
VALUES ('56255249','**HANNA 70'S**','32','5')`
example (CORRECT)
INSERT INTO Article (ARV_ARTICLE, ARV_NAME, ARV_BRAND_ID, ARV_GROUP)
VALUES ('56255249','**HANNA 70S**','32','5')`
I resolve the problem with a subtract
来源:https://stackoverflow.com/questions/9985746/there-was-an-error-parsing-the-query-token-line-number-1-token-line-offset