Search code examples
asp.net-mvc-3rawsql

ASP.NET MVC3 Raw Sql Update


I'm sure I'm doing a simple mistake. I try to run raw Update statement in my ASP.NET MVC3 project.

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

The lines above return the error: "Incorrect syntax near 'RejectionTypeID'." I debug the project but the query seems right.

"UPDATE Proposals SET  TypeID=1 RejectionTypeID=1 Title='SomeText' Explanation='Some Longer Text' RejectionCause='' WHERE ID=1 "

RejectionTypeID is a foreign key, depends on ID of the table RejectionTypes and they are of type int, telling in case there's a violation. Any idea what I'm doing wrong here?


Solution

  • after each variable set add "," (comma).