title: Parameterized Update
body: <p>I am trying to update a record in an access file (.accdb). I am trying to use the .net OleDbCommand and OleDbParameters. I am also trying to use a generic model and store all of the commands and parameters in the System.Data.Common abstract equivalents so that I can        easily switch over to SQL Server (which I do plan to do)</p>
  
  <p><strong>So here is the actual command being used</strong></p>
  
  <p><strong>EDIT 2/2/2013 - 9:10pm</strong>
  the command.ExecuteNonQuery is inside the method named ExecuteNonQuery()
  the connectionString and command are defined in the DataAccess class constructor</p>
  
  <pre><code>public class DataAccess
  {
  
      private string connectionString;
      private DbConnection connection;
      private DbCommand command;
      private DbDataReader reader;
      private DataTable data;
  
      public DataAccess()
      {
          connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
  
          switch (ConfigurationSettings.AppSettings["DataBaseType"])
          {
              case "oledb":
                  connection = new OleDbConnection(connectionString);
                  command = new OleDbCommand(string.Empty, (OleDbConnection)connection);
                  break;
              case "SQL":                 
                  connection = new SqlConnection(connectionString);
                  command = new SqlCommand(string.Empty, (SqlConnection)connection);
                  break;
              default:
                  break;
          }
  
      }
  
      public void ExecuteNonQuery(string SQL, params DbParameter[] parameters)
      {
          command.CommandType = CommandType.Text;
          command.CommandText = SQL;
          command.Parameters.AddRange(parameters);
  
          try
          {
              command.Connection.Open();
  
              try
              {
                  command.ExecuteNonQuery();
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              finally
              {
                  command.Connection.Close();
              }
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }
  
      public DbParameter NewParameter(string name, object value)
      {
          DbParameter param;
  
          switch (ConfigurationSettings.AppSettings["DataBaseType"])
          {
              case "oledb":
                  param = new OleDbParameter(name, value);
                  break;
              case "SQL":
                  param = new SqlParameter(name, value);
                  break;
              default:
                  param = null;
                  break;
          }
  
          return param;
      }
  </code></pre>
  
  <p><strong>These are the properties in the App.Config File</strong></p>
  
  <p><code>&lt;add key="DataBaseType" value="oledb"/&gt;</code></p>
  
  <p><code>&lt;add key="ConnectionString" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=data.accdb"/&gt;</code></p>
  
  <p>Now the problem is when using parameters in an update statement, the update never happens and also never throws an error. Here is the code for it.</p>
  
  <p><strong>EDIT 2/2/2013 - 9:10pm</strong>
  the function DataAccess.NewParameter is in the first code block</p>
  
  <pre><code>DALayer.ExecuteNonQuery("UPDATE TileTypes SET Title = @Title, Picture = @Picture, Color = @Color WHERE ID = @ID",
   DALayer.NewParameter("@Title", titleTextBox.Text.Trim()),
   DALayer.NewParameter("@Picture", typePictureBox.ImageLocation),
   DALayer.NewParameter("@Color", colorButton.BackColor.ToArgb()),
   DALayer.NewParameter("@ID", id));
  </code></pre>
  
  <p>I have copied the query into access and replaced all of the parameter names with the actual data being passed, this works fine. I have tried replacing all of the parameters in the SQL text to the ? character to no effect. I have tried enclosing all of the table and column names in brackets [] also to no effect.</p>
  
  <ul>
  <li>ID is an AutoNumber field</li>
  <li>Title is a Text field</li>
  <li>Picture is a Text field</li>
  <li>Color is a Long Integer field</li>
  </ul>
  
  <p>This is some example data that was copied directly from the parameters in the watch window for Visual Studio:</p>
  
  <ul>
  <li>"Edit"  (title)</li>
  <li>-1      (color)</li>
  <li>"data\images\Edit_000000.jpg" (picture)</li>
  <li>740     (id)</li>
  </ul>
  
  <p>That ID does exist in the database and was unchanged after the query executed.</p>
  
  <p><strong>EDIT 2/2/2013 - 9:10pm</strong>
  I am not sure how to check which database is actually being updated, the only thing I could think of was that using the same connection string and connection object I did an insert statement with the same ExecuteNonquery method and it worked in the database I was viewing. And the update statement works just fine like this (without parameters):</p>
  
  <pre><code>DALayer.ExecuteNonQuery("UPDATE TileTypes SET Title = '" + titleTextBox.Text + 
  "', Color = " + colorButton.BackColor.ToArgb() + ", Picture = '" + 
  imageLocation + "' WHERE ID = " + id);
  </code></pre>
  
  <p><strong>EDIT 2/2/2013 - 9:41pm</strong>
  I have used everything.exe to search my computer for all of the data.accdb files on my computer, I have found no actual .accdb files besides the original but I did find these .lnk files, I do not believe they could have altered this process but I will mention it anyway</p>
  
  <p>data.accdb.LNK</p>