Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OLEDB数据适配器。读取Excel文件时的日期格式_C#_Excel_Oledbdataadapter - Fatal编程技术网

C# OLEDB数据适配器。读取Excel文件时的日期格式

C# OLEDB数据适配器。读取Excel文件时的日期格式,c#,excel,oledbdataadapter,C#,Excel,Oledbdataadapter,我有带IMEX选项的连接字符串所有类型都转换为字符串: strConnectionString=string.FormatProvider=Microsoft.ACE.OLEDB.12.0;数据源=\{0}\;扩展属性=\Excel 12.0 Xml;HDR=否;IMEX=1;\;,strFile; 我使用下面的代码将xslx文件读入DataTable DataTable=新的DataTablename; 字符串sql=从[+name+]中选择*; OleDbDataAdapter SQLAda

我有带IMEX选项的连接字符串所有类型都转换为字符串:

strConnectionString=string.FormatProvider=Microsoft.ACE.OLEDB.12.0;数据源=\{0}\;扩展属性=\Excel 12.0 Xml;HDR=否;IMEX=1;\;,strFile; 我使用下面的代码将xslx文件读入DataTable

DataTable=新的DataTablename; 字符串sql=从[+name+]中选择*; OleDbDataAdapter SQLAdapter=新的OleDbDataAdapter; OleDbCommand selectCMD=新的OleDbCommandsql,SQLConn; SQLAdapter.SelectCommand=selectCMD; SQLAdapter.Filltable; 程序在两台计算机上读取相同的文件

当程序在第一台计算机上运行时,我得到的日期像字符串31.03.2021。当程序在第二台计算机上运行时,我得到的日期类似于字符串3/31/2021

我无法在两台计算机上获得相同的日期格式。我已经试过:

在Windows设置中更改语言格式

设置

设置


没有任何帮助

我找不到任何解决方案。所以我开始使用选项IMEX=0,而不是IMEX=1。 日期被正确读取为日期时间类型

 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
 table.Locale = new CultureInfo("en-US");