2010-12-15 138 views
0

Je suis en train de mettre à jour ma base de données via Datagridview. Voici mon code Update_Button:Syntaxe incorrecte près de 'WHERE'

public void SaveDataSet(DataTable table) 
{ 

    foreach (DataRow row in table.Rows) 
    { 

    SqlCommand cmd2 = new SqlCommand(
     @"update dbo.JobStatus 
     SET ShipTransmitStatus = @TransmitStatus, 
      ShipTrackingNumber = @TrackingNum, 
      Carrier = @Carrier, 
      ShipmentProcessedBy = @ProcessedBy, 
      ShipMethodTransmitted = @MethodTransmitted, 
     WHERE JobTableId = @JobID ", _mySqlConnec); 

    //Updated the parameters to the SQL Query! 
    cmd2.Parameters.Add(new SqlParameter("@TransmitStatus", row["Status"].ToString())); 
    cmd2.Parameters.Add(new SqlParameter("@TrackingNum", row["Tracking#"].ToString())); 
    cmd2.Parameters.Add(new SqlParameter("@Carrier", row["Carrier"])); 
    cmd2.Parameters.Add(new SqlParameter("@ProcessedBy", row["ProcessedBy"].ToString())); 
    cmd2.Parameters.Add(new SqlParameter("@MethodTransmitted", row["MethodTransmitted"].ToString())); 
    cmd2.Parameters.Add(new SqlParameter("@JobID", row["JobID"].ToString())); 

    cmd2.Connection = _mySqlConnec; 
    _mySqlConnec.Open(); 
    cmd2.ExecuteNonQuery(); 
    _mySqlConnec.Close(); 
    } 


} 

Et voici mon instruction SELECT:

SELECT dbo.InvoiceLineDetail.JobNumber as Job#,dbo.InvoiceLineDetail.PatientName, 
     dbo.InvoiceLineDetail.CustomerAccountName as Name, COALESCE(InvoiceLineDetail.ShipAddressAddr2 + ' ','') + COALESCE(InvoiceLineDetail.ShipAddressAddr3+' ','') as Address, 
     dbo.InvoiceLineDetail.ShipAddressCity as City, dbo.InvoiceLineDetail.ShipAddressState as State, 
     dbo.InvoiceLineDetail.ShipAddressPostalCode as ZipCode, dbo.InvoiceLineDetail.ShipAddressCountry as Country , dbo.JobStatus.ShipTransmitStatus as Status, dbo.JobStatus.ShipTrackingNumber as Tracking#, dbo.JobStatus.Carrier, dbo.JobStatus.ShipMethodTransmitted as MethodTransmitted, 
     dbo.JobStatus.DateShipTransmitProcessed as DateProcessed, dbo.JobStatus.ShipmentProcessedBy as ProcessedBy, dbo.JobStatus.Critical, dbo.JobStatus.JobTableId as JobID, dbo.JobStatus.InvoiceStatus, 
     dbo.InvoiceLineDetail.Quantity, dbo.InvoiceLineDetail.ChargeGroup 
     FROM dbo.InvoiceLineDetail INNER JOIN 
     dbo.View_JobsToShipCount ON dbo.InvoiceLineDetail.CustomerAccountName = dbo.View_JobsToShipCount.CompanyName INNER JOIN 
     dbo.JobStatus ON dbo.InvoiceLineDetail.JobID = dbo.JobStatus.JobTableId 
     WHERE (dbo.InvoiceLineDetail.ChargeGroup = N'Lens') 

Je reçois une erreur: Syntaxe incorrecte près 'WHERE'. Pourrait trouver le problème :(

Répondre

8

Supprimer la dernière virgule de:

ShipMethodTransmitted = @MethodTransmitted, 

-à-dire changer à:

ShipMethodTransmitted = @MethodTransmitted 

En réponse générale pour ces types d'erreurs:

  1. Regardez autour du mot clé suggéré dans le message d'erreur
  2. Si votre ror message vous a donné une ligne à laquelle l'erreur est à regarder. ligne

C'est exactement ce que j'ai fait maintenant. J'ai regardé près de là et j'ai vu la virgule supplémentaire.

3
ShipMethodTransmitted = @MethodTransmitted, 

supprimer la virgule après @Method ...

?

3

Dans la fonction SaveDataSet, la commande SQL comporte une virgule supplémentaire avant la clause WHERE.