ecs*_*usa 5 .net c# double excel
我有以下C#代码:
static void Main(string[] args)
{
double a = 1.2d;
double b = 3.1d;
double c = 0.17241379310344829;
double d = 0.25d;
Console.WriteLine("{0:G17}", a * b * c * d);
string CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
using(var conn = new OleDbConnection(string.Format(CONNECTION_STRING, @"C:\TEMP\anyExcelFile.xlsx")))
{
conn.Open();
using(var sqlCmd = conn.CreateCommand())
{
sqlCmd.CommandType = System.Data.CommandType.Text;
sqlCmd.CommandText = "INSERT INTO [Sheet1$A1:A] VALUES (1)";
sqlCmd.ExecuteNonQuery();
}
}
Console.WriteLine("{0:G17}", a * b * c * d);
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,Console.WriteLine给我以下结果:
0.16034482758620688
0.16034482758620691
Run Code Online (Sandbox Code Playgroud)
您需要在C:\ TEMP\anyExcelFile.xlsx(带有名为Sheet1的工作表)上有一个excel文件才能运行它.
如果我评论ExecuteNonQuery行,然后再次运行,我得到:
0.16034482758620688
0.16034482758620688
Run Code Online (Sandbox Code Playgroud)
为什么执行excel会导致双重操作返回不同的结果?