我确定我犯了一个简单的错误。我尝试在我的 ASP.NET MVC3 项目中运行原始更新语句。
if (Request["btApprove"] == (string)ViewBag._Approve)
{
query = "UPDATE Proposals SET "
+ " TypeID=" + Request["ProposalTypes"]
+ " RejectionTypeID=" + Request["RejectionTypes"]
+ " Title='" + Request["taProposalTitle"] + "'"
+ " Explanation='" + Request["taProposalDescription"] + "'"
+ " RejectionCause='" + Request["taRejectionCause"] + "'"
+ " WHERE ID=" + Request["txProposalNo"] + " ";
db.Database.ExecuteSqlCommand(query);
}
上面的行返回错误:“'RejectionTypeID' 附近的语法不正确。” 我调试项目,但查询似乎正确。
"UPDATE Proposals SET TypeID=1 RejectionTypeID=1 Title='SomeText' Explanation='Some Longer Text' RejectionCause='' WHERE ID=1 "
RejectionTypeID是一个外键,取决于表RejectionTypes的ID ,它们的类型是int,以防万一发生违规。知道我在这里做错了什么吗?