UPDATE Query : Incorrect Syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Thomas
    New Member
    • Dec 2010
    • 1

    UPDATE Query : Incorrect Syntax

    Hello All:

    I have a button in my windows forms which UPDATES every table. However, I am getting error SQLException was unhandled. Incorrect syntax near '='.

    This is my code in Update Button:

    Code:
    var sql = new StringBuilder();
                        sql.AppendLine("UPDATE dbo.JobStatus");
                        sql.AppendLine("Set ShipTrackingNumber = @ShipTrackingNumber");
                        sql.AppendLine(", ShipMethodTransmitted = @ShipMethodTransmitted");
                        sql.AppendLine(", DateShipTransmitProcessed = @DateShipTransmitProcessed");
                        sql.AppendLine(", ShipmentProcessedBy = @ShipmentProcessedBy");
                        sql.AppendLine(", Critical = @Critical");
                        sql.AppendLine(", ShipTransmitStatus = @ShipTransmitStatus");
                        sql.AppendLine("Where jobtableId = @jobTableId");
    
                        cmd.Connection = sqlConnection1;
                        cmd.CommandText = sql.ToString();
                        cmd.Parameters.AddWithValue("@TrackingNumber", row.Cells[7].FormattedValue);
                        cmd.Parameters.AddWithValue("@ShipMethodTransmitted", row.Cells[8].FormattedValue);
                        
                        cmd.Parameters.AddWithValue("@DateShipTransmitProcessed", row.Cells[9].FormattedValue);
                        cmd.Parameters.AddWithValue("@ShipmentProcessedBy", row.Cells[10].FormattedValue);
                        cmd.Parameters.AddWithValue("@Critical", row.Cells[11].FormattedValue);
                        cmd.Parameters.AddWithValue("@ShipTransmitStatus", row.Cells[13].FormattedValue);
                        cmd.Parameters.AddWithValue("@jobTableId", row.Cells[5].FormattedValue);
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Is there a way for you to display the t-sql stored in the sql variable? From there we can see what's wrong with your T-SQL.

    Good Luck!!!

    ~~ CK

    Comment

    Working...