Insert IntX Value into MS Access Database

Feb 19, 2014 at 10:30 AM
Hi All:

I want to insert value 10101590720614783876211228540930 into database.
I am creating table using following command : "create table " + TableId + "(Key Text,PNumber int)";
When I fire insert query on database, it stores the above value as 1.01015907206148E+31.
Why it doesn't store value as it is even if I mentioned type as text?
How to retrieve original(10101590720614783876211228540930 ) value from this(1.01015907206148E+31) value?
Please advise.

Feb 20, 2014 at 10:39 AM
It's not IntX-related question but anyway - you can't store arbitrary-precision integer as "int" because MS Access integer has limited precision - that's why you are losing precision in this case.

With MS Access and IntX two options you actually have are:
  • Use IntX.GetInternalState() method and store IntX as two fields - binary (VARBINARY) + BIT for sign
  • Store as string (VARCHAR) and parse after loaded from the DB. I suggest storing IntX as hexadecimal number in this case (base=16) since both ToString() and Parse() will work faster (in linear time) in this case. And you will need to explicitly convert IntX to/from string