What's wrong in that SQL update statement?
using c# and ADO.Net
database : Access
-----------------------------------------------------------------------------------------------------
I am using an access data base called HotelDataBase.MDB with a table called Register in which 14-columns that are respectively
First Name [Text], Sure Name [Text], Age [Int], ID [Int], Tel [Int], Gender [Text], Country [Text], Room Number [Int], Room Type [Text], Room Class [Text], Number of Nights [Int], Start Date Month [Text], Start Date Day [Int], Start Date Year [Int]
and I've a Form in which a text box called "updateIDTextBox" and Search Button to search for the specified id in that Text Box.
if the id exists, all data will be displayed in their editable places in the form as
First Name : Name------------Last Name : MyName
Age : 22 ------------ID : 1320065 and So On...
Then any of these data can be changed then the user clicks on the Save Button to Update data of the specified id in the search text box
the update statement is
string updateQuery = "Update Register Set First Name = '" + firstNameTextBox.Text + "',Sure Name = '" + sureNameTextBox.Text + "',Age = " + ageTextBox.Text + ",ID = " + idTextBox.Text + ",Tel = " + telTextBox.Text + ",Gender = '" + genderComboBox.Text + "',Country = '" + countryComboBox.Text + "',Room Number = " + roomNumberTextBox.Text + ",Room Type = '" + roomTypeComboBox.Text + "',Room Class = '" + roomClassComboBox.Text + "',Number of Nights = " + noOfNightsTextBox.Text + ",Sart Date Month = '" + monthComboBox.Text) + "',Start Date Day = " + dayComboBox.Text + ",Start Date Year = " + yearComboBox.Text + " Where ID = " + updateIDTextBox.Text + ";";
Unfortunately i received a syntax error in the update statement
this is the code of Save Button
DataBaseOperations.CON = new OleDbConnection(DataBaseOperations.CONNECTION);
string updateQuery = "Update Register Set FirstName = '" + firstNameTextBox.Text + "',SureName = '" + sureNameTextBox.Text + "',Age = " + ageTextBox.Text + ",ID = " + idTextBox.Text + ",Tel = " + telTextBox.Text + ",Gender = '" + genderComboBox.Text + "',Country = '" + countryComboBox.Text + "',RoomNumber = " + roomNumberTextBox.Text + ",RoomType = '" + roomTypeComboBox.Text + "',RoomClass = '" + roomClassComboBox.Text + "',NumberofNights = " + noOfNightsTextBox.Text + ",SartDateMonth = '" + monthComboBox.Text + "',StartDateDay = " + dayComboBox.Text + ",StartDateYear = " + yearComboBox.Text + ", Where ID = " + updateIDTextBox.Text + ";";
DataBaseOperations.COM = new OleDbCommand(updateQuery, DataBaseOperations.CON);
DataBaseOperations.CON.Open();
DataBaseOperations.COM.ExecuteNonQuery();
DataBaseOperations.CON.Close();
clearAllFieldsButton.Enabled = true;
MessageBox.Show("Update Process of Habitant : " + firstNameTextBox.Text.ToString() + " " + sureNameTextBox.Text.ToString() + "\nHas Been Done Successfully", "Successful Update");