更新查询的位置附近的语法不正确

Ram*_*Ram 1 c# sql asp.net

这是我用来更新表的更新查询.它抛出一个异常"在哪里附近的语法不正确"为什么这个例外?我不知道.

    public bool UpdateLocationCountintoMerchantPackage(int PackageID, long MerchantID,int LocationCount)
    {
        try
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@packageID",PackageID),
                new SqlParameter("@merchantID",MerchantID ),
                new SqlParameter("@locationCount",LocationCount )
            };
            string CommandText = string.Empty;  
            CommandText = "Update Merchant_Package SET LocationCount Where MerchantID=@MerchantID";
            string ConnectionString = DbConnectionStrings.GetDbConnectionString();
            SqlHelper.ExecuteNonQuery(ConnectionString, System.Data.CommandType.Text, CommandText, parameters);
            return true;

        }
        catch (SqlException ex)
        {
            LogError("Error Occurred When Saving Merchant Location Count Data : MerchantID:" + MerchantID.ToString(), ex);
            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这个函数是从

protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
{

        UpdatePaymentInfo();
        string QueryString = Request.QueryString.ToString();
        if (string.Equals(QueryString, "MerchantProfilePages"))
        {
            Response.Redirect(ApplicationData.URL_ADD_PROFILE_PAGE, false);
            Merchant mrchnt = new Merchant();
            int PackId = mrchnt.PackageID;
            int x = GetLocationCount() + 1;
            mrchnt.UpdateLocationCountintoMerchantPackage(PackId, merchantId, x);
        }
Run Code Online (Sandbox Code Playgroud)

cod*_*ger 13

这是你的"SET LocationCount"的一个问题 - 你没有把它设置为任何东西.这就是为什么它抱怨WHERE.

  • 你确实传递了参数,但你没有使用它."更新Merchant_Package SET LocationCount = @ LocationCount Where MerchantID = @ MerchantID" (3认同)