2010-08-12 3 views
1

Voici la requête de mise à jour que j'utilise pour mettre à jour une table. Cela me jette une exception "Syntaxe incorrecte près de" Pourquoi cette exception? Je n'ai aucune idée.Syntaxe incorrecte à proximité de l'emplacement d'une requête de mise à jour

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 [email protected]"; 
      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; 
     } 
    } 

cette fonction est appelée à partir

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

Répondre

13

C'est un problème avec votre « SET LocationCount » - vous n'êtes pas le mettre égal à quoi que ce soit. C'est pourquoi il se plaint du WHERE.

+0

Mais j'ai passé valeur LocationCount de « x ». Est-ce faux?? – Ram

+3

Vous avez effectivement passé le paramètre, mais vous ne l'avez pas utilisé. "Mettre à jour Merchant_Package SET LocationCount = @ LocationCount où MerchantID = @ MerchantID" – WillfulWizard

+0

public bool UpdateLocationCountintoMerchantPackage (int ID de package, ID marchand long, int LocationCount) Lorsque je débogue, il me montre la valeur de x. Donc j'ai pensé que je le passais. Laissez-moi essayer et revenir. Merci!! – Ram

3

Utiliser SQL comme:

Update Merchant_Package SET [email protected] 
Where [email protected] 

Votre erreur sur la 1ère ligne a été signalé, quand, où a été rencontré

+0

Merci les gars !!! Impressionnant. Vous m'apprenez beaucoup de choses !! – Ram