David Smith

David Smith

  • NA
  • 2k
  • 0

Sql semicolon Access MDB error

Dec 5 2012 6:30 PM
I am getting an error saying missing semicolon in the SQL statement. I writing to an access database. Review below.

  string sql = "INSERT INTO tblServiceEvent ( ServiceID, ContactID, NieghborID,ContactFrom,ContactAbout, " +
                                                       "ServiceEventDate, ServiceEventType, ServiceEventStatus, ServiceEvent,TakenByID, FollowUpDate, " +
                                                       "FollowUpDate,CompleteByID, CompleteDate, Comments, SysCreateBy, SysCreateDate, SysUpdateBy, SysUpdateDate )  " +
                                                       "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Where ServiceID = ? ;";

                using (OleDbConnection sqlConnection = new OleDbConnection(Properties.Settings.Default.careuser2_5cXPConnectionString))
                {
                    sqlConnection.Open();

                    OleDbDataAdapter sqlCommandAdapter = new OleDbDataAdapter();

                    using (OleDbCommand sqlCommand = new OleDbCommand(sql, sqlConnection))
                    {
                        sqlCommand.Parameters.AddWithValue("ServiceID", ServiceID);
                        sqlCommand.Parameters.AddWithValue("ContactID", ContactID);
                        sqlCommand.Parameters.AddWithValue("NieghborID", NieghborID);
                        sqlCommand.Parameters.AddWithValue("ContactFrom", ContactFrom);
                        sqlCommand.Parameters.AddWithValue("ContactAbout", ContactAbout);
                        sqlCommand.Parameters.AddWithValue("ServiceEventDate", ServiceEventDate);
                        sqlCommand.Parameters.AddWithValue("ServiceEventType", ServiceEventType);
                        sqlCommand.Parameters.AddWithValue("ServiceEventStatus", ServiceEventStatus);
                        sqlCommand.Parameters.AddWithValue("ServiceEvent", ServiceEvent0);
                        sqlCommand.Parameters.AddWithValue("FollowUpDate", FollowUpDate);
                        sqlCommand.Parameters.AddWithValue("CompleteByID", CompleteByID);
                        sqlCommand.Parameters.AddWithValue("CompleteDate", CompleteDate);
                        sqlCommand.Parameters.AddWithValue("Comments", Comments);
                        sqlCommand.Parameters.AddWithValue("SysCreateBy", SysCreateBy);
                        sqlCommand.Parameters.AddWithValue("SysCreateDate", SysCreateDate);
                        sqlCommand.Parameters.AddWithValue("SysUpdateDate", SysUpdateDate);
                        sqlCommand.Parameters.AddWithValue("SysUpdateDate", SysUpdateDate);

                        sqlCommandAdapter.UpdateCommand = sqlCommand;

                        int rowsAffected = 0;
                        if ((rowsAffected = sqlCommandAdapter.UpdateCommand.ExecuteNonQuery()) > 0)