Title的语法错误

时间:2015-07-12 14:05:13

标签: c# syntax

班级档案:

  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'附近的语法不正确。”

这是我的aspx.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();
    }

1 个答案:

答案 0 :(得分:0)

您在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";

(我还删除了那里的+运算符,因为它们没有任何功能。)