title: Insert decimal value into Currency Access field
body: <p><strong>Short background:</strong> I am replacing an outdated, Visual Based based program with a C#-based one. With the program comes an Access (JET) based database which is already in use. For now, I want to connect to the current database for practical reasons. However in the foreseeable future I'd like to replace it with SQL Server.</p>
  
  <p><strong>Question:</strong> The database stores financial information using the Access 'Currency' datatype. In C#, I use 'Decimal' to represent financial information. Naturally, I get an error when I try an INSERT or UPDATE-query to store the Decimal in the Currency-field (actually, I get an error once and with it, it automatically changes the datatype of that specific record to Decimal). I'm not sure what the best way to solve this problem is:</p>
  
  <ol>
  <li>Transform the Decimal into Currency in my program and inserting it after. Is this even possible (C# says the values from the field are of the DBNull-type since it doesn't know Currency)? If yes, how do I do this?</li>
  <li>Change the datatype of the field into Decimal. <em>Will I risk corrupting financial information when I do this?</em></li>
  <li>Any other/better suggestions?</li>
  </ol>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <p>The exact error message:</p>
  
  <pre><code>System.Data.Odbc.OdbcException (0x80131937): ERROR [07006] 
  [Microsoft][ODBC Microsoft Access-stuurprogramma]Inbreuk op kenmerk van beperkt gegevenstype
  </code></pre>
  
  <p>It's Dutch and translates to <code>Restricted data type attribute violation</code></p>
  
  <p>My UPDATE code:</p>
  
  <pre><code>public Boolean setFuelCosts(int rentID, Decimal fuelcosts)
          {
              string conString = lem2;
              string queryString = "UPDATE rental SET fuel = ? WHERE rentid = ?";
              OdbcCommand command = new OdbcCommand(queryString);
              command.Parameters.Add("@fuel", OdbcType.Decimal).Value = fuelcosts;
              command.Parameters.Add("@rentid", OdbcType.Int).Value = rentID;
              return factory.executeUpdateCommand(conString, command);
          }
  
  public Boolean executeUpdateCommand(String conString, OdbcCommand command)
          {
              bool result = false;
              using (OdbcConnection connection = new OdbcConnection(conString))
              {
                  try
                  {
                      command.Connection = connection;
                      command.CommandType = CommandType.Text;
                      connection.Open();
                      int i = command.ExecuteNonQuery();
                      result = (i &gt;= 1);
                      connection.Close();
                  }
                  catch (Exception exc)
                  {
                      System.Windows.Forms.MessageBox.Show(exc.Message);
                      System.Windows.Forms.MessageBox.Show(exc.StackTrace);
                  }
              }
              return result;
          }
  </code></pre>