data error when reading csv file in C# winforms(在 C# winforms 中读取 csv 文件时出现数据错误)
问题描述
我有一个 C# winforms 正在从 csv 文件中读取一列.它正确读取了 4 列中的 3 列.csv 文件中的第 4 列是 S4
,但数据集显示的是 4
.
I have a C# winforms that is reading a column from a csv file. It reads 3 of the 4 columns correct. The 4th column in the csv file is S4
, but the dataset is displaying 4
.
代码是:
string conn = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0; Data"
+ "Source={0}; Extended Properties=""text;HDR=YES;FMT=DELIMITED""",
strDirectoryPath);
OleDbConnection oleDBConn = new OleDbConnection(conn);
oleDBConn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * FROM [" + strFileName + "]",
conn);
DataSet ds = new DataSet();
da.Fill(ds);
csv 数据样本为:
AA0013 Incident Incident S4
AA0016 Incident Incident S3
AA0017 Incident Incident S3
AA0023 Incident Incident S3
AA0076 Issue Issue S3
AA0079 Incident Incident S6
AA0082 Issue Issue S6
AA0084 Incident Incident S6
AA0085 Incident Incident S6
这是什么原因造成的,我该如何解决?
What would cause this and how can I resolve it?
推荐答案
这是因为有时 OLEDB 提供程序会自动检测列的数据类型,并尝试将该列中的所有值转换为它检测到的特定数据类型.要解决此问题,您需要指定 schema.ini 文件,该文件将保存有关每列及其数据类型的信息,以便 OLEDB 不会尝试将任何列隐式转换为自己喜欢的数据类型:)...
This is because some times OLEDB provider auto detect the data type of the column and try to convert all the values in that column to a specific data type it detects. to solve this problem you need to specify the schema.ini file that will hold information about each column and its data type so that OLEDB dont try to implicitly convert any column to its own favorite data type :)...
这里是完整的指南..http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspx
问候.
这篇关于在 C# winforms 中读取 csv 文件时出现数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# winforms 中读取 csv 文件时出现数据错误


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01