sqlwrite only writes 6 digits to Access Database

10 次查看(过去 30 天)
I'm trying to write an Excel date code to an Access database in the format: 44798.6912268518
but when I open the Access database, the date code is written as 44798.7.
Is there a way to write more than 6 digits to an Access database without changing the data type to a string?

回答(1 个)

Rahul
Rahul 2024-11-7,9:48
I understand that currently while accessing data from database, you are obtaining the number in a short format. You can consider defining 'format long' before writing the data which can consider approximately 15 decimal places for double-precision numbers. Here is an example:
% I have taken 'conn' and 'tablename' as variables for connection with the database, can be adjusted
% Set the display format to long
format long
dateCode = 44798.6912268518;
data = table(dateCode, 'VariableNames', {'yourFieldName'});
sqlwrite(conn,tablename,data)
Another approach can be to use the 'vpa' function provided by the Symbolic Math Toolbox which enables to define number of significant decimal places required. Here is an example:
dateCode = vpa(44798.6912268518, 30); % Here I have taken 30 as an example for required decimal places
data = table(dateCode, 'VariableNames', {'yourFieldName'});
sqlwrite(conn,tablename,data)
You can refer to the following MathWorks documentations to know more about these functions:
Hope this helps! Thanks.

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by