UPDATE Statement Syntax Error RRS feed

  • Question

  • Below is my code. The last lines I tried inserting was the "Percent" Field. If I comment out anything that has to do with "Percent", the code works. I am still a novice at this so any and all help would be greatly appreciative. 
       string UpdateSFM = "UPDATE HSFDBFEEDRATE SET SFM = @SFM,"
                + "RPM = @RPM,"
                + "IPR = @IPR,"
                + "IPM = @IPM,"
                + "BRAND = @BRAND,"
                + "RedSFM = @RedSFM,"
                + "RedRPM = @RedRPM,"
                + "RedIPR = @RedIPR,"
                + "RedIPM = @RedIPM,"
                + "Percent = @Percent WHERE ID =" + ID;

                OleDbCommand Insert = new OleDbCommand(UpdateSFM, DrillConnection);
                Insert.Parameters.Add("@SFM", OleDbType.VarChar).Value = SFMText.Text;
                Insert.Parameters.Add("@RPM", OleDbType.VarChar).Value = RPMText.Text;
                Insert.Parameters.Add("@IPR", OleDbType.VarChar).Value = IPRText.Text;
                Insert.Parameters.Add("@IPM", OleDbType.VarChar).Value = FEEDText.Text;
                Insert.Parameters.Add("@Brand", OleDbType.VarChar).Value = comboBox2.SelectedItem;
                Insert.Parameters.Add("@RedSFM", OleDbType.VarChar).Value = ReducedSFM.Text;
                Insert.Parameters.Add("@RedRPM", OleDbType.VarChar).Value = ReducedRPM.Text;
                Insert.Parameters.Add("@RedIPR", OleDbType.VarChar).Value = ReducedIPR.Text;
                Insert.Parameters.Add("@RedIPM", OleDbType.VarChar).Value = ReducedIPM.Text;
                Insert.Parameters.Add("@Percent", OleDbType.VarChar).Value = PerRed.Text;
    Wednesday, October 21, 2009 3:31 PM


All replies

  • What's your datatable at database for percent field?

    Wednesday, October 21, 2009 3:48 PM
  • The datatable is called "HSFDBFEEDRATE", and the field name is "Percent". 
    Wednesday, October 21, 2009 3:55 PM
  • What happens when it doesn't work? Do you get an error? If so, what is it?

    It would also help to know what type of database that you are working with. If it's Access, Percent is a reserved keyword. It would need to either be enclosed in brackets or renamed in the SQL statement.

    If the error is a data type mismatch then I would suspect that your parameter data type is incorrect and the value isn't being converted properly.

    More detail concerning the problem would be helpful.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, October 21, 2009 3:59 PM
  • The database is Access. I tried changing the name and it does work properly now. Thank you very much. Do you know where I could find what Reserved words to avoid while programming in C# for Access and any other database for that matter?

    Wednesday, October 21, 2009 4:10 PM
  • The following links should help:

    List of Microsoft Jet 4.0 reserved words

    List of reserved words in Access 2002 and in later versions of Access

    For other databases you would probably need to check the documentation. SQL Server uses TRANSACT SQL so you could Bing on that if you need the language reference.

    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Yichun_Feng Wednesday, October 28, 2009 2:21 AM
    Wednesday, October 21, 2009 4:16 PM