解析查询时出错。 [令牌行号= 1,令牌行偏移= 52,令牌错误=)]

时间:2012-04-03 00:47:30

标签: sql razor webmatrix

尝试向我的SQl数据库插入数据时,我收到以下错误System.Data.SqlServerCe.SqlCeException: There was an error parsing the query. [ Token line number = 1,Token line offset = 52,Token in error = ) ] 我输入数据的代码行如下:

@{
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);
    }
}

我正在尝试将文件上传到我的服务器并将文件名添加到我的数据库中。错误显然是第15行。

2 个答案:

答案 0 :(得分:4)

跟踪逗号是我的猜测。将sql insert语句更改为:

var SQLINSERT = "INSERT INTO Games (Name, file_path) " + "VALUES (@0, @1)";

答案 1 :(得分:0)

我的案子中的问题是在句子的中间有'人物

示例(错误)

INSERT INTO Article (ARV_ARTICLE, ARV_NAME, ARV_BRAND_ID, ARV_GROUP) 
             VALUES ('56255249','**HANNA 70'S**','32','5')`

示例(正确)

INSERT INTO Article (ARV_ARTICLE, ARV_NAME, ARV_BRAND_ID, ARV_GROUP) 
             VALUES ('56255249','**HANNA 70S**','32','5')`

我用减法

解决了这个问题