title: Data type mismatch using Decimal parameter- OleDb, C#, Access
body: <p>Okay, so I'm trying to send private members that have been updated in my program to an access database. However whenever I run the program and press the save button, I get a "Data type mismatch in criteria expression" exception thrown at me.</p>
  
  <p>Here is the code snippet that I am using. It is throwing the exception at the da.Update command. So I know it has something to do with my update command or my parameters.
  I also commented out the repetitive parts since I have been trying to narrow down the issue.</p>
  
  <p>OleDbConnection conn = new OleDbConnection(ConnString);</p>
  
  <pre><code>        string sql = @" SELECT * FROM Account where AccountID = '" + accountName + @"'";
  
          string update = @" UPDATE Account SET
                          Cash = '@Cash'";/*, PaidInCapital = '@PaidInCapital',
                          TotalRetainedEarnings = '@TotalRetainedEarnings',
                          StockholdersEquity = '@StockholdersEquity',
                          CommonStock = '@CommonStock', PreferredStock = '@PreferredStock',
                          TreasuryStock = '@TreasuryStock', CashDividends = '@CashDividends',
                          StockDividends = '@StockDividends', @"TotalNumberPreferred = '@TotalNumberPreferred',
                          PreferredMarketPrice = '@PreferredMarketPrice', PreferredPar = '@PreferredPar',
                          Cumulative = '@Cumulative', TotalNumberCommon = '@TotalNumberCommon',
                          CommonMarketPrice = '@CommonMarketPrice', CommonPar = '@CommonPar',
                          NumberTransactTreasuryStock = '@NumberTransactTreasuryStock',
                          AvgPriceTreasury = '@AvgPriceTreasury'";*/
  
  
          try
          {
              OleDbDataAdapter da = new OleDbDataAdapter();
  
              da.SelectCommand = new OleDbCommand(sql, conn);
  
              AccountDatabaseDataSet ds = new AccountDatabaseDataSet();
  
              da.Fill(ds, "Account");
  
              DataTable dt = ds.Tables["Account"];
  
              dt.Rows[0][1] = cash;
              /*dt.Rows[0][2] = paidInCapital;
              dt.Rows[0][3] = totalRetainedEarnings;
              dt.Rows[0][4] = stockholdersEquity;
              dt.Rows[0][5] = commonStock;
              dt.Rows[0][6] = preferredStock;
              dt.Rows[0][7] = treasuryStock;
              dt.Rows[0][8] = cashDividends;
              dt.Rows[0][9] = stockDividends;
              dt.Rows[0][10] = totalNumberPreferred;
              dt.Rows[0][11] = preferredMarketPrice;
              dt.Rows[0][12] = preferredPar;
              dt.Rows[0][13] = preferredRate;
              dt.Rows[0][14] = cumulative;
              dt.Rows[0][15] = totalNumberCommon;
              dt.Rows[0][16] = commonMarketPrice;
              dt.Rows[0][17] = commonPar;
              dt.Rows[0][18] = numberTransactTreasury;
              dt.Rows[0][19] = avgPriceTreasury;*/
  
              OleDbCommand cmd = new OleDbCommand(update, conn);
  
              cmd.Parameters.Add("@Cash", OleDbType.Decimal, 18, "Cash");
              /*cmd.Parameters.Add("@PaidInCapital", OleDbType.Decimal, 18, "PaidInCapital");
              cmd.Parameters.Add("@TotalRetainedEarnings", OleDbType.Decimal, 18, "TotalRetainedEarnings");
              cmd.Parameters.Add("@StockholdersEquity", OleDbType.Decimal, 18, "StockholdersEquity");
              cmd.Parameters.Add("@CommonStock", OleDbType.Decimal, 18, "CommonStock");
              cmd.Parameters.Add("@PreferredStock", OleDbType.Decimal, 18, "PreferredStock");
              cmd.Parameters.Add("@TreasuryStock", OleDbType.Decimal, 18, "TreasuryStock");
              cmd.Parameters.Add("@CashDividends", OleDbType.Decimal, 18, "CashDividends");
              cmd.Parameters.Add("@StockDividends", OleDbType.Decimal, 18, "StockDividends");
              cmd.Parameters.Add("@TotalNumberPreferred", OleDbType.Integer, 16, "TotalNumberPreferred");
              cmd.Parameters.Add("@PreferredMarketPrice", OleDbType.Decimal, 10, "PreferredMarketPrice");
              cmd.Parameters.Add("@PreferredPar", OleDbType.Decimal, 10, "PreferredPar");
              cmd.Parameters.Add("@PreferredRate", OleDbType.Decimal, 5, "PreferredRate");
              cmd.Parameters.Add("@Cumulative", OleDbType.Boolean, 2, "Cumulative");
              cmd.Parameters.Add("@TotalNumberCommon", OleDbType.Integer, 16, "TotalNumberCommon");
              cmd.Parameters.Add("@CommonMarketPrice", OleDbType.Decimal, 10, "CommonMarketPrice");
              cmd.Parameters.Add("@CommonPar", OleDbType.Decimal, 10, "CommonPar");
              cmd.Parameters.Add("@NumberTransactTreasuryStock", OleDbType.Integer, 16, "NumberTransactTreasuryStock");
              cmd.Parameters.Add("@AvgPriceTreasury", OleDbType.Decimal, 10, "AvgPriceTreasury");*/
  
  
              da.UpdateCommand = cmd;
              da.Update(ds, "Account");
  </code></pre>
  
  <p>Essentially narrowed down to this if you take out the commented parts:</p>
  
  <pre><code>OleDbConnection conn = new OleDbConnection(ConnString);
  
          string sql = @" SELECT * FROM Account where AccountID = '" + accountName + @"'";
  
          string update = @" UPDATE Account SET
                          Cash = '@Cash'";
          try{
              OleDbDataAdapter da = new OleDbDataAdapter();
  
              da.SelectCommand = new OleDbCommand(sql, conn);
  
              AccountDatabaseDataSet ds = new AccountDatabaseDataSet();
  
              da.Fill(ds, "Account");
  
              DataTable dt = ds.Tables["Account"];
  
              dt.Rows[0][1] = cash;
  
              OleDbCommand cmd = new OleDbCommand(update, conn);
  
              cmd.Parameters.Add("@Cash", OleDbType.Decimal, 18, "Cash");
  
              da.UpdateCommand = cmd;
              da.Update(ds, "Account");
           }
  </code></pre>
  
  <p>So, basically what I have is an "Account" table that I want to set the second[1] column equal to the private member variable "cash" that is of type decimal. Then I set my parameters for the "@Cash" param where the OleDbType is a Decimal, the size is 18, and the column in the access database is "Cash". Finally I update the "Account" Table with this value.</p>
  
  <p>Now I have tried changing .Decimal in my oledbtype to every possible type in the list, but it never seems to work and even some of the exceptions state it as a "Decimal type that cannot convert to DateTime", for instance. So I am led to believe that the oledbtype is not the problem. I have also tried messing with the size in the parameter and that has not worked either. </p>
  
  <p>I have tried to explain this the best I can, but if there is anything else that would be beneficial to help solve this problem I will provide it.</p>