1

I'm approaching a access 2007 database using Microsoft.ACE.OLEDB.12.0. It contains a table created using

CREATE TABLE reccs(decimalField decimal(28,9))

which has to have this precision and scale. I'm adding a row using

string s = "INSERT INTO [reccs]([minQuantity]) VALUES(@minQuantity)";
object o = ...;
oleDbCommand = new OleDbCommand(s, conn);
OleDbParameter param = new OleDbParameter("minQuantity", o);
oleDbCommand.Parameters.Add(param).Value = o;
oleDbCommand.ExecuteNonQuery(); 

Sometimes (depending on the exact decimal in o) this throws a System.Data.OleDb.OleDbException: The decimal field's precision is too small to accept the numeric you attempted to add. I read this post, about adjusting decimal precision in c#, but it feels hacky to solve the problem like that, and I am unsure whether it will GUARANTEE that the exception will not get thrown. Any better suggestions?

Community
  • 1
  • 1
willem
  • 2,617
  • 5
  • 26
  • 38
  • 1
    Have you tried passing the value as a string? Try and let Access parse the string data, you might get better results. – Paul Sasik Sep 20 '10 at 16:30
  • This works, but I don't understand why. And: should I use the same approach when passing double/int/long values to access in this manner? – willem Sep 21 '10 at 07:12

0 Answers0