标题处语法错误

本文关键字:错误 语法 标题 | 更新日期: 2023-09-27 18:02:22

类文件:

  public int RewardUpdate(string rId,string rDesc, string rCategory,string rTitle,int rPoint)
    {
        string queryStr = "UPDATE Reward SET r_Desc = @r_Desc," + " r_Category = @r_Category " + " r_Title = @r_Title " + " r_Point = @r_Point " + " WHERE r_Id = @r_Id";
        SqlConnection conn = new SqlConnection(connStr);
        SqlCommand cmd = new SqlCommand(queryStr, conn);
        cmd.Parameters.AddWithValue("@r_Id", rId);
        cmd.Parameters.AddWithValue("@r_Desc", rDesc);
        cmd.Parameters.AddWithValue("@r_Category", rCategory);
        cmd.Parameters.AddWithValue("@r_Title", rTitle);
        cmd.Parameters.AddWithValue("@r_Point", rPoint);
        conn.Open();
        int nofRow = 0;
        nofRow = cmd.ExecuteNonQuery();
        conn.Close();
        return nofRow;
    }

上面写着"附加信息:'r_Title'附近语法错误。"

这是我的asp .cs:

 protected void gv_Reward_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int result = 0;
        reward rd = new reward();
        GridViewRow row = (GridViewRow)gv_Reward.Rows[e.RowIndex];
        // id is created on the spot.
        string id = gv_Reward.DataKeys[e.RowIndex].Value.ToString();
        string rId = ((TextBox)row.Cells[0].Controls[0]).Text;
        string rDesc = ((TextBox)row.Cells[1].Controls[0]).Text;
        string rCategory = ((TextBox)row.Cells[2].Controls[0]).Text; 
        string rTitle = ((TextBox)row.Cells[3].Controls[0]).Text;
        string rPoint = ((TextBox)row.Cells[4].Controls[0]).Text;
        result = rd.RewardUpdate(rId, rDesc, rCategory, rTitle, int.Parse(rPoint));
        if (result > 0)
        {
            Response.Write("<script>alert('Reward updated succesfully');</script>");
        }
        else
        {
            Response.Write("<script>alert('Reward not updated');</script>");
        }
        gv_Reward.EditIndex = -1;
        bind();
    }

标题处语法错误

您的SQL语句中缺少一些逗号:

string queryStr = "UPDATE Reward SET r_Desc = @r_Desc," + " r_Category = @r_Category " + " r_Title = @r_Title " + " r_Point = @r_Point " + " WHERE r_Id = @r_Id";
应该

string queryStr = "UPDATE Reward SET r_Desc = @r_Desc, r_Category = @r_Category, r_Title = @r_Title, r_Point = @r_Point WHERE r_Id = @r_Id";

(我还删除了+操作符,因为它们没有功能。)