开发者

Incorrect Syntax near Where for an Update query

开发者 https://www.devze.com 2023-01-11 02:28 出处:网络
Here is the update query which i am using to update a table. It throws me an exception \"Incorrect Syntax near Where\" Why is that exception for? i have no idea.

Here is the update query which i am using to update a table. It throws me an exception "Incorrect Syntax near Where" Why is that exception for? i have no idea.

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

this function is called from

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


It's an issue with your "SET LocationCount" - you're not setting it equal to anything. That's why it's complaining about the WHERE.


Use SQL like:

Update Merchant_Package SET LocationCount=@LocationCount
Where MerchantID=@MerchantID

Your error on the 1st line was reported when WHERE was encountered

0

精彩评论

暂无评论...
验证码 换一张
取 消