tags:

views:

60

answers:

2

Hello,

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);
        }
+13  A: 

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.

codykrieger
But i have passed LocationCount value from 'x'. Is that wrong??
Ram
You did indeed pass in the parameter, but you have not used it."Update Merchant_Package SET LocationCount=@LocationCount Where MerchantID=@MerchantID"
Willfulwizard
public bool UpdateLocationCountintoMerchantPackage(int PackageID, long MerchantID,int LocationCount) When i debug, it shows me the value of x. So i thought i am passing it. Let me give it a try and come back. Thanks!!
Ram
+3  A: 

Use SQL like:

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

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

Henk Holterman
Thanks Guys!!! Awesome. You guys teaching me hell lot!!
Ram