none
Update query not update the record in access DB RRS feed

  • Question

  • show Error

    {"Syntax error in string in query expression ''121212122where SeqNo=  000000000013'."}

    connection.Open();
    OleDbCommand command1 = new OleDbCommand();
    command1.Connection = connection;
    string query = " update PatientData set PatientName='" + NameTextBox.Text + "where SeqNo=  " + analyzerIDTextBox.Text + " ";
    MessageBox.Show(query);
    command1.CommandText = query;
    command1.ExecuteNonQuery();
    connection.Close();

    record not updae kindly advise me  how to solves this issue i think i am mistake in query.

    <tfoot></tfoot>
    PatientData
    PatientID SeqNo MRNo PatientName
    1 000000000001 1803130001 hjhjhjhj
    2 000000000002 1803130002 jhkjhkj
    3 000000000003 1803130003 ioiuoioiuoi


    Tuesday, March 13, 2018 6:47 PM

Answers

  • Until you implement Parameterised Queries, show your current program and try the next query:

    string query = "update PatientData set PatientName = '" + NameTextBox.Text + "' where SeqNo = '" + analyzerIDTextBox.Text + "'";

    • Marked as answer by saqsaqPK Wednesday, March 14, 2018 5:54 PM
    Wednesday, March 14, 2018 7:45 AM

All replies

  • Seems that you need some apostrophes:

    string query = "update PatientData set PatientName = '" + NameTextBox.Text + "' where SeqNo = '" + analyzerIDTextBox.Text + "'";

    And also you need Parameterised Queries in order to avoid the problem of apostrophes.

    • Proposed as answer by Cor Ligthert Tuesday, March 13, 2018 7:18 PM
    Tuesday, March 13, 2018 6:59 PM
  • 121212122where SeqNo

    You have the where of the Where clause slammed up against the textbox.text  data.

    NameTextBox.Text + " where SeqNo=

    It should be as you see with a space before the where to separate the SQL statement from the data.

    Tuesday, March 13, 2018 7:04 PM
  • its not working kindly advise
    Wednesday, March 14, 2018 5:16 AM
  • Show the current code and the errors.
    Wednesday, March 14, 2018 5:30 AM
  • Code run but data not insert  in Database . 
    Wednesday, March 14, 2018 5:33 AM
  • In order to insert, consider the INSERT statement.

    If you mean that UPDATE does not modify the existing row, then make sure that the WHERE part is correct.

    Also, check that you are examining the right Access file.

    Wednesday, March 14, 2018 6:14 AM
  • TRY CATCH RECORD FOLLOWING ERROR 

    • Edited by saqsaqPK Wednesday, March 14, 2018 6:25 AM UPDATE
    Wednesday, March 14, 2018 6:20 AM
  • Until you implement Parameterised Queries, show your current program and try the next query:

    string query = "update PatientData set PatientName = '" + NameTextBox.Text + "' where SeqNo = '" + analyzerIDTextBox.Text + "'";

    • Marked as answer by saqsaqPK Wednesday, March 14, 2018 5:54 PM
    Wednesday, March 14, 2018 7:45 AM
  • Thanks Problem Solved 
    Wednesday, March 14, 2018 5:54 PM