There was an error parsing the query. [ Token line

2019-07-19 01:45发布

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.

2条回答
Bombasti
2楼-- · 2019-07-19 01:54

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

查看更多
萌系小妹纸
3楼-- · 2019-07-19 01:57

Trailing comma is my guess. change sql insert statement to this:

var SQLINSERT = "INSERT INTO Games (Name, file_path) " + "VALUES (@0, @1)";
查看更多
登录 后发表回答