Search code examples
c#ms-accessoledboledbdataadapter

OleDbDataAdapter error after change in database


I haven been trying to figure this out all day and just couldn't find my mistake. I have an ms-access database and a c# program that is supposed to update the data in the db. Unfortunately I keep getting System.Data.OleDb.OleDbException: Syntaxerror in update statement.

I am using OleDbConnectionand OleDbDataAdapter and everything (except for one column) was working perfectly. I couldn't figure out why I kept getting the above mentioned error for that column (it was formatted just like the others -> text), so I deleted the column and created it again. Now I get the error for every single alteration I try to make.

public void changeFields(string id, string name, string famName, string department) {
   DataSet myDS = new DataSet();
   using (OleDbConnection conn = new OleDbConnection(connectionString)) {
      conn.Open();
      OleDbDataAdapter adapter = new OleDbDataAdapter();
      adapter.SelectCommand = new OleDbCommand("SELECT * FROM Table WHERE ID = '"+ id +"', conn);
      OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);

      myDS.Tables["Table"].Rows[0]["Name"] = name;
      myDS.Tables["Table"].Rows[0]["FamilyName"] = famName;
      myDS.Tables["Table"].Rows[0]["Department"] = department;

      adapter.Update(myDS, "Table");
      conn.Close();
   }
}

The names of the columns are correct and if I

Console.WriteLine(myDS.Tables["Table"].Rows[0]["Name"];

right before I try to update. I actually get the correctly changed version. The error always occurs for line adapter.Update(); Is it possible that access rearranges or messes some index up when I insert a column into the database?

Help would be very much appreciated


Solution

  • I figured it out! The problem was that I had a reserved keyword as a column name. Now it all works perfectly fine